BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


.NET and XML
String Handling Application using ASP.NET
XML Serialization and .Net
Dynamic Method Invocation in .NET using Reflection API
Using XML classes in .Net
Pass node sets to XSLT stylesheets using .NET
Output a directory as XML using .NET
.Net, COM Interoperability and Word Object Model
WS-Routing for .NET endpoints
Using XML and XSLT in VB.NET Jeopardy
Symmetric Encryption/Decryption with .NET
XInclude.NET 1.0
EXSLT.NET 1.0
How to read a XML file using XmlTextReader?
How to compare a XML element with XmlTextReader?
How to verify if an element is empty with XmlTextReader and IsEmptyElement?
How to check if the XML elements contains any attributes with XmlTextReader
How to avoid to read the XML declaration with XmlTextReader?
How to create a XML file with XmlTextWriter?
Is it possible to add attributes with XmlTextWriter?
How to Write a Comment to a XML File with XmlTextWriter and WriteComment?


 
 

<< XSLT 


By Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First Posted 02/14/2002
Times viewed 3481

XML Web Services and ASP.NET


This post contains attachments
v20020214233758.zip 

Summary This article gives an idea on how to create a Web Service, how to consume the Web Service and its interfaces.

In this article, I will discuss

  • How to build an XML Web Service using the ASP.NET FrameWork?
  • How to create a proxy of the XML Web Service?
  • How to create an instance of the proxy and accessed its exposed interfaces?

Creation of Web Service using ASP.NET

In ASP.NET, the XML Web Service files have .asmx extension. Here I will try to add, subtract, multiply and divide two integers. This example is to show how really, we can implement the concept of web services and to analyze its advantages.

Refer to the code of SimpleCalculator.asmx file.

In this example, we created a class SimpleCalculator using C# language as XML Web Service which exposes Add, Subtract, Multiply and Division methods. The interfaces returns the result of type integer. You can extend this example to different types like float,etc.
The first line in the example is a Web Service directive, which is used to identify the language and class of the Web Service.
Any method that is to be exposed as a method of an XML Web Service must have WebMethodAttribute applied to it and it must be declared using the public keyword.
The WebService, which is System.Web.Services.WebServiceAttribute class is an optional attribute that can be applied to a public class.

This XML Web Service can be browsed through Internet Explorer browser. To see how the asmx file looks like please downlaod the attachment where I posted my web service code, which shows how .asmx file exposes its intefaces.

You can look at WSDL(Web Services Description Language) by typing SimpleCalculator.asmx?wsdl
To see disco file, type SimpleCalculator.asmx?disco
DISCO is Microsoft publishing technology into .NET.
UDDI(Universal Description, Discovery, and Integration) is an industry wide publishing technology.

To test the exposed intefaces, click on one of the methods. Then we will see two text boxes with Invoke button. When we give input to these boxes, the Invoke button returns the result in the form of an XML document.

Creation of Proxy for Web Service

To consume the Web Service, we need to create a proxy for the Web Service. Then create the instance of the proxy and invoke its methods.

How to create a proxy for Web Service?

 To create the proxy, you can use Web Services Description Lanugage Tool (WSDL.exe) to generate a Web Service client proxy class.
The following is the command line to create the proxy class:

If you develop .asmx file using C# language then

wsdl /l:cs /o:SimpleCalculator.cs http://pandu/SimpleCalculator.asmx?wsdl /n:CalculatorApplication

If you develop .asmx file using VB language then

wsdl /l:vb /o:SimpleCalculator.vb http://pandu/SimpleCalculator.asmx?wsdl /n:CalculatorApplication

Then compile the resultant file to create dll. The following is the command line to create dll.

For C#:
csc /out:SimpleCalculator.dll /t:library /r:system.web.dll, system.dll, system.xml.dll, system.web.service.dll, system.data.dll SimpleCalculator.cs

For VB:
vbc /out:SimpleCalculator.dll /t:library /r:system.web.dll, system.dll, system.xml.dll, system.web.service.dll, system.data.dll SimpleCalculator.vb

Create an instance of Proxy Client in .aspx file(Web Form)

Refer to the CalTest.aspx file in code section.

In this .aspx file, I used two text box controls, one dropdown control and a button. These are server side controls. This .aspx file is actually a Web Form.
The following is the figure of web form I used to test the Web Service.

I test the above given code with Beta2 .NET SDK version on Windows 2000 Professional OS.

If you have any questions or issues, please do feel free to contact me.

Additional information


Rate this article on a scale of 1 to 10 (15 votes, average 7)

Your vote :  

<< XSLT 



Latest comments on this article
Admin
By Vivek Deshpande on 5/7/2008 10:42:33 AM
Hello All, I am calling third party php webservice in my asp.net application. LocalhostXYZ srvLogin = new Localhost.XYZ(); Localhost.LogonResponseArray arryObj = new LogonResponseArray(); arryObj = srvLogin.logon("abc", "pqr", "xyz"); Where logon() is API from Php Web service. Return type of logon() method is LogonResponseArray class which is of array type. I am facing one problem that arryObj returns null value. So can any one tell me how can i get proper value. Thanks Vivek Deshpande


Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML