PROGRAMMING WEB SERVICES

Similar documents
Web Services in.net (1)

Ambientes de Desenvolvimento Avançados

Creating and Consuming XML Web Services

Web Services with ASP.NET. Asst. Prof. Dr. Kanda Saikaew Department of Computer Engineering Khon Kaen University

Q Lately I've been hearing a lot about WS-Security. What is it, and how is it different from other security standards?

Web services can convert your existing applications into web applications.

Praktikum im Bereich Praktische Informatik Entwicklung eines Ray-Tracing Systems. computer graphics & visualization

Creating XML Report Web Services

Creating Form Rendering ASP.NET Applications

CHAPTER 10: WEB SERVICES

Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer

Creating Web Services Applications with IntelliJ IDEA

A Web Services Created Online Training and Assessment Scheme

How to consume a Domino Web Services from Visual Studio under Security

Web Services API Developer Guide

Building and Using Web Services With JDeveloper 11g

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

SQL Server 2005: Web Services

Web-Service Example. Service Oriented Architecture

Hands-On Lab. Lab 01: Getting Started with SharePoint Lab version: Last updated: 2/23/2011

Lab 8: ASP.NET 2.0 Configuration API and Health Monitoring

The presentation explains how to create and access the web services using the user interface. WebServices.ppt. Page 1 of 14

VB.NET - WEB PROGRAMMING


Ajax Development with ASP.NET 2.0

Author: Gennaro Frazzingaro Universidad Rey Juan Carlos campus de Mostòles (Madrid) GIA Grupo de Inteligencia Artificial

Accessing Data with ADOBE FLEX 4.6

How to test and debug an ASP.NET application

Crystal Reports for Visual Studio.NET

Service-Oriented Architecture, Web Services, XML and Higher Education

DEVELOPING CONTRACT - DRIVEN WEB SERVICES USING JDEVELOPER. The purpose of this tutorial is to develop a java web service using a top-down approach.

INTERNET PROGRAMMING AND DEVELOPMENT AEC LEA.BN Course Descriptions & Outcome Competency

Integrating Siebel CRM with Microsoft SharePoint Server

WHITE PAPER. TimeScape.NET. Increasing development productivity with TimeScape, Microsoft.NET and web services TIMESCAPE ENTERPRISE SOLUTIONS

T320 E-business technologies: foundations and practice

Module 13 Implementing Java EE Web Services with JAX-WS

Crystal Reports. For Visual Studio.NET. Designing and Viewing a Report in a Windows Application

Yarmouk University Faculty of Science and Information Technology Department of Computer Information Systems CIS 282 Developing Web Applications

Configuring.NET based Applications in Internet Information Server to use Virtual Clocks from Time Machine

QuickBooks Web Connector Programmer s Guide

Getting started with OWASP WebGoat 4.0 and SOAPUI.

JAVASCRIPT AND COOKIES

Building Web Services with Apache Axis2

WhitePaper. Web services: Benefits, challenges, and a unique, visual development solution

Glassfish, JAVA EE, Servlets, JSP, EJB

Grid Computing. Web Services. Explanation (2) Explanation. Grid Computing Fall 2006 Paul A. Farrell 9/12/2006

.NET Overview. David Smith. Today s s Topics. Why am I here? A tool. Microsoft s s Vision for.net

WA2087 Programming Java SOAP and REST Web Services - WebSphere 8.0 / RAD 8.0. Student Labs. Web Age Solutions Inc.

Secure Authentication and Session. State Management for Web Services

This section provides a 'Quickstart' guide to using TestDriven.NET any version of Microsoft Visual Studio.NET

Demo: Controlling.NET Windows Forms from a Java Application. Version 7.3

Crystal Reports. For Visual Studio.NET. Reporting Off ADO.NET Datasets

WCF WINDOWS COMMUNICATION FOUNDATION OVERVIEW OF WCF, MICROSOFTS UNIFIED COMMUNICATION FRAMEWORK FOR.NET APPLICATIONS

Consuming and Producing Web Services with WST and JST. Christopher M. Judd. President/Consultant Judd Solutions, LLC

The Modeling of Communication with Other. Systems in Process Automation Applications

WEB SERVICES. Revised 9/29/2015

webcrm API Getting Started

Quartz.Net Scheduler in Depth

CRM Setup Factory Installer V 3.0 Developers Guide

Performance Testing for Ajax Applications

JBoss SOAP Web Services User Guide. Version: M5

BPEL. A Step by Step Guide: Model-Driven Generation with. Enterprise Architect. T his document will teach you how to use the Business Process

Implementing a WCF Service in the Real World

Introduction to Testing Webservices

Enterprise Application Development in SharePoint 2010

CHAPTER 13: INTEGRATION OPTIONS

Web Service Development Using CXF. - Praveen Kumar Jayaram

Lesson 4 Web Service Interface Definition (Part I)

Developing, Deploying, and Debugging Applications on Windows Embedded Standard 7

SilverlightViewerForReportingServices2008GettingStartedExample.zip

Lab Introduction to Web Services

Consuming and Producing Web Services with Web Tools. Christopher M. Judd. President/Consultant Judd Solutions, LLC

Deploying Microsoft Operations Manager with the BIG-IP system and icontrol

Address Phone & Fax Internet

Terms and Definitions for CMS Administrators, Architects, and Developers

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

Creating SOAP and REST Services and Web Clients with Ensemble

Oracle Service Bus Examples and Tutorials

Introduction to Web services for RPG developers

Internationalization and Web Services

Braindumps.C questions

Developing and Implementing Windows-Based Applications With Microsoft Visual C#.NET and Microsoft Visual Studio.NET

Introduction to Visual Studio and C#

JOURNAL OF OBJECT TECHNOLOGY

A SharePoint Developer Introduction. Hands-On Lab. Lab Manual HOL8 Using Silverlight with the Client Object Model C#

ASP.NET 5 SOMEONE MOVED YOUR CHEESE. J. Tower

Authoring for System Center 2012 Operations Manager

Performance Analysis of webmethods Integrations using Apache JMeter Information Guide for JMeter Adoption

Installing the ASP.NET VETtrak APIs onto IIS 5 or 6

STK Terrain Server Installation Guide

Sage 100 ERP. ebusiness Web Services Installation and Reference Guide

Developer Tutorial Version 1. 0 February 2015

Creating a Java application using Perfect Developer and the Java Develo...

CUSTOMISING CRUISECONTROL.NET

A standards-based approach to application integration

ITS. Java WebService. ITS Data-Solutions Pvt Ltd BENEFITS OF ATTENDANCE:

Census. di Monitoring Installation User s Guide

Extensibility. vcloud Automation Center 6.0 EN

IBM SPSS Collaboration and Deployment Services Version 6 Release 0. Single Sign-On Services Developer's Guide

TECHNICAL DOCUMENTATION SPECOPS DEPLOY / APP 4.7 DOCUMENTATION

Transcription:

PROGRAMMING WEB SERVICES I. SOAP: SOAP is a lightweight, message-based protocol built on XML, HTTP, and SMTP. Two other protocols are desirable, but not required, for a client to use a SOAP-enabled web service: a description of the methods provided by a particular service that can be understood and acted upon by clients, and a description of all such services available at a particular site or URL. The first of these is provided in.net by the Web Service Description Language (WSDL) protocol, jointly developed by Microsoft, IBM, and others. Two other protocols have been proposed for discovery: UDDI, a joint effort by a number of companies including IBM and Microsoft, and Discovery, a proprietary offering from Microsoft. WSDL and Discovery WSDL is an XML schema used to describe the available methods -- the interface -- of a web service. Discovery enables applications to locate and interrogate web service descriptions, a preliminary step for accessing a web service. It is through the discovery process that web service clients learn that a service exists, what its capabilities are, and how to properly interact with it. A Discovery (.disco) file provides information to help browsers determine the URLs at any web site at which web services are available. When a server receives a request for a.disco file, it generates a list of some or all of the URLs at that site that provide web services. Server-side Support The plumbing necessary to discover and invoke web services is integrated into the.net Framework and provided by classes within the System.Web.Services namespace. Creating a web service requires no special programming on your part; you need only write the implementing code, add the [WebMethod] attribute, and let the server do the rest. Client-side Support You make use of a web service by writing client code that acts as though it were communicating directly with the host server by means of a URL. However, in reality, the client interacts with a proxy. The job of the proxy is to represent the server on the client machine, to bundle client requests into SOAP messages that are sent on to the server, and to retrieve the responses that contain the result. II. i) BUILDING A WEB SERVICE To illustrate the techniques used to implement a web service in C# using the services classes of the.net Framework, build a simple calculator and then make use of its functions over the Web. Begin by specifying the web service. To do so, define a class that inherits from System.Web.Services.WebService. The easiest way to create this class is to open Visual Studio and create a new C# Web Service project. The default name that Visual Studio provides is WebService1. Visual Studio.NET creates a skeleton web service and even provides a Web Service example method for you to replace with your own code, as shown in the following example. 1

Skeleton Web Class generated by Visual Studio.NET using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; namespace WSCalc /// <summary> /// Summary description for Service1. /// </summary> public class Service1 : System.Web.Services.WebService public Service1( ) //CODEGEN: This call is required by // the ASP.NET Web Services Designer InitializeComponent( ); #region Component Designer generated code //Required by the Web Services Designer private IContainer components = null; /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent( ) /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) if(disposing && components!= null) components.dispose( ); base.dispose(disposing); #endregion // WEB SERVICE EXAMPLE // The HelloWorld( ) example service // returns the string Hello World // To build, uncomment the following lines // then save and build the project // To test this web service, press F5 2

// [WebMethod] // public string HelloWorld( ) // // return "Hello World"; // Create five methods: Add( ), Sub( ), Mult( ), Div( ), and Pow( ). Each takes two parameters of type double, performs the requested operation, and then returns a value of the same type. For example, here is the code for raising a number to some specified power: public double Pow(double x, double y) double retval = x; for (int i = 0;i < y-1;i++) retval *= x; return retval; To expose each method as a web service, you simply add the [WebMethod] attribute before each method declaration. WSDL and Namespace Web service will use a Web Service Description Language (WSDL) XML document to describe the web-callable end points. Within any WSDL document, an XML namespace must be used to ensure that the end points have unique names. The default XML namespace is http://tempuri.org, but you will want to modify this before making your web service publicly available. We can change the XML namespace by using the WebService attribute: [WebService(Namespace= "http://www.libertyassociates.com/webservices/")] Calculator Web Service Program: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; namespace WSCalc [WebService(Namespace="http://www.libertyAssociates.com/webServices/")] public class Service1 : System.Web.Services.WebService 3

public Service1( ) //CODEGEN: This call is required by the //ASP.NET Web Services Designer InitializeComponent( ); #region Component Designer generated code //Required by the Web Services Designer private IContainer components = null; /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent( ) /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) if(disposing && components!= null) components.dispose( ); base.dispose(disposing); #endregion [WebMethod] public double Add(double x, double y) return x+y; [WebMethod] public double Sub(double x, double y) return x-y; [WebMethod] public double Mult(double x, double y) return x*y; [WebMethod] public double Div(double x, double y) return x/y; [WebMethod] public double Pow(double x, double y) 4

double retval = x; for (int i = 0;i < y-1;i++) retval *= x; return retval; When you build this project with Visual Studio.NET, a DLL is created in the appropriate subdirectory of your Internet server. ii) TESTING YOUR WEB SERVICE If you open a browser to your web service's URL (or invoke the browser by running the program in Visual Studio.NET), you get an automatically generated, server-side web page that describes the web service, as shown in the fig below. Test pages such as this offer a good way to test your web service. Web Service Web Page Clicking a method brings you to a page that describes the method and allows you to invoke it by typing in parameters and pressing the Invoke button. The following fig illustrates this. 5

Test Page For a Web Service Method If you type 3 into the first value field and 4 into the second field, you will have asked the web service to raise 3 to the fourth power. The result is an XML page describing the output, as shown in the fig below: XML Output for a Web Service Method Notice that the URL encodes the parameters of 3 and 4, and the output XML shows the result of 81 (3*3*3*3 = 81). iii) VIEWING THE WSDL CONTRACT The web service is described in WSDL. You can see the WSDL document by appending?wsdl to the web service URL, like this: http://localhost/wscalc/service1.asmx?wsdl The browser displays the WSDL document, as shown in FIG below 6

Sample WSDL Output For Calculator Web Service Each method is fully described in a structured XML format. This is the information used by SOAP to allow the client browser to invoke your web service methods on the server. III. CREATING THE PROXY Before you can create a client application to interact with the calculator web service, you must first create a proxy class. The folks at Microsoft have provided a tool called wsdl that generates the source code for the proxy based on the information in the WSDL file. To create the proxy, enter wsdl at the Windows command-line prompt, followed by the path to the WSDL contract. For example, you might enter: wsdl http://localhost/wscalc/service1.asmx?wsdl The result is the creation of a C# client file named Service.cs, an excerpt of which appears in the following example. You must add the namespace WSCalc because you'll need it when you build your client (the tool does not insert it for you). Sample Client Code To Access the Calculator Web Service using System.Xml.Serialization; using System; using System.Web.Services.Protocols; using System.Web.Services; namespace WSCalc [System.Web.Services.WebServiceBindingAttribute( Name="Service1Soap", 7

Namespace="http://www.libertyAssociates.com/webServices/")] public class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol public Service1( ) this.url = "http://localhost/wscalc/service1.asmx"; [System.Web.Services.Protocols.SoapDocumentMethodAttribute( "http://www.libertyassociates.com/webservices/add", RequestNamespace= "http://www.libertyassociates.com/webservices/", ResponseNamespace= "http://www.libertyassociates.com/webservices/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle= System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] public System.Double Add(System.Double x, System.Double y) object[] results = this.invoke("add", new object[] x,y); return ((System.Double)(results[0])); public System.IAsyncResult BeginAdd(System.Double x, System.Double y, System.AsyncCallback callback, object asyncstate) return this.begininvoke("add", new object[] x, y, callback, asyncstate); public System.Double EndAdd(System.IAsyncResult asyncresult) object[] results = this.endinvoke(asyncresult); return ((System.Double)(results[0])); This complex code is produced by the WSDL tool to build the proxy DLL you will need when you build your client. The file uses attributes extensively, but with your working knowledge of C# you can extrapolate at least how some of it works. The file starts by declaring the Service1 class that derives from the class SoapHttpClientProtocol, which occurs in the namespace called System.Web.Services.Protocols public class Service1 System.Web.Services.Protocols.SoapHttpClientProtocol The constructor sets the URL property inherited from SoapHttpClientProtocol to the URL of the.asmx page you created earlier. The Add( ) method is declared with a host of attributes that provide the SOAP goo to make the remote invocation work. The WSDL application has also provided asynchronous support for your methods. For 8

example, for the Add( ) method, it also created BeginAdd( ) and EndAdd( ). This allows you to interact with a web service without performance penalties. To build the proxy, place the code generated by WSDL into a C# Library project in Visual Studio.NET and then build the project to generate a DLL. Be sure to write down the location of that DLL, as you will need it when you build the client application. To test the web service, create a very simple C# Console application. The only trick is that in your client code you need to add a reference to the proxy DLL just created. Once that is done, you can instantiate the web service, just like any locally available object: WSCalc.Service1 thewebsvc = new WSCalc.Service1( ); You can then invoke the Pow( ) method as if it were a method on a locally available object: for (int i = 2;i<10; i++) for (int j = 1;j <10;j++) Console.WriteLine( "0 to the power of 1 = 2", i, j, thewebsvc.pow(i, j)); This simple loop creates a table of the powers of the numbers 2 through 9, displaying for each the powers 1 through 9. The complete source code and an excerpt of the output is shown below A Client Program to test the calculator web service using System; // driver program to test the web service public class Tester public static void Main( ) Tester t = new Tester( ); t.run( ); public void Run( ) int var1 = 5; int var2 = 7; // instantiate the web service proxy WSCalc.Service1 thewebsvc = new WSCalc.Service1( ); // call the add method Console.WriteLine("0 + 1 = 2", var1, var2, thewebsvc.add(var1, var2)); // build a table by repeatedly calling the pow method for (int i = 2;i<10; i++) for (int j = 1;j <10;j++) 9

Console.WriteLine("0 to the power of 1 = 2", i, j, thewebsvc.pow(i, j)); Output (excerpt): 5 + 7 = 12 2 to the power of 1 = 2 2 to the power of 2 = 4 2 to the power of 3 = 8 2 to the power of 4 = 16 2 to the power of 5 = 32 2 to the power of 6 = 64 2 to the power of 7 = 128 2 to the power of 8 = 256 2 to the power of 9 = 512 3 to the power of 1 = 3 3 to the power of 2 = 9 3 to the power of 3 = 27 3 to the power of 4 = 81 3 to the power of 5 = 243 3 to the power of 6 = 729 3 to the power of 7 = 2187 3 to the power of 8 = 6561 3 to the power of 9 = 19683 Your calculator service is now more available than you might have imagined through the web protocols of HTTP-Get, HTTP-Post, or SOAP. Your client uses the SOAP protocol, but you could certainly create a client that would use HTTPGet: http://localhost/wscalc/service1.asmx/add?x=23&y=22 In fact, if you put that URL into your browser, the browser will respond with the following answer: <?xml version="1.0" encoding="utf-8"?> <double xmlns="http://www.libertyassociates.com/webservices/">45</double> The key advantage SOAP has over HTTP-Get and HTTP-Post is that SOAP can support a rich set of datatypes, including all of the C# intrinsic types (int, double, etc.), as well as enums, classes, structs, and ADO.NET DataSets, and arrays. Also, while HTTP-Get and HTTP-Post protocols are restricted to name/value pairs of primitive types and enums, SOAP's rich XML grammar offers a more robust alternative for data exchange. STEPS FOR CREATING THE PROXY open visual studio command prompt got to f: paste the url copied in (that is the url chnaged to wsdl) press enter a file will be created in C# In the visual studio c# console type."namespace wscalc" after using* statements. 10

In the command prompt, type csc /t:library Service.cs click enter A dll file will be created in F: got to new->project->console application write the client program in the console Go to colution explorer. right click reference Add reference(i.e add system.we.services) click ok again rightclick references->add refernces In the window display.click browse.and add the dll file created earlier click ok 11