How to create and use a Web service proxy class

Source: Internet
Author: User
Tags reference tostring web services wsdl
web| How to create and use Web service proxy classes



The Web service proxy is a programming language file that supports. NET and is generated automatically by the WSDL tools provided by the. NET Framework. The proxy class does not contain any application logic. Instead, he contains transport logic about how to pass parameters and retrieve results, as well as a list of methods and prototypes in Web services. The proxy class can be created from any WSDL file.



You can access a Web service as you would access a COM object. To access a Web service, you need to create a proxy class from the WSDL document for the Web service on the local computer.. NET provides a tool named WSDL.exe to automatically generate proxy class files. The following is a detailed description of its creation and use process:



1, a new ASP application (#C) project, the project named Teachshow, in the Teachshow project to create a folder Charpter8, under the folder to create a new Web service, named: Computer.asmx

2, switch to Code view, write the following code:

[WebMethod (description= for Add operations, Enablesession=false)]

public int Add (int a,int b)

{

return a+b;

}



[WebMethod (description= for subtracting operations, Enablesession=false)]

public int Sub (int a,int b)

{

return a+b;

}



[WebMethod (description= for multiplication operations, Enablesession=false)]

public int Multi (int a,int b)

{

return a*b;

}



[WebMethod (description= for division operations, Enablesession=false)]

public double devide (int a,int b)

{

Return Convert.todouble (a)/convert.todouble (b);



3, according to F5 compile the whole project (this step must be done, if not to do the 4th step can not be achieved)



4, open ms.net 2003 command Prompt tool, enter: C:\>WSDL http://localhost/TeachShow/Charpter8/FirstAndUse/Computer.asmx/n: Computernamespace, where Computernamespace is a custom namespace. The prompts are as follows:

Microsoft (R) Web Services Description Language utility

[Microsoft (R). NET Framework, version 1.1.4322.573]

Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.



Writing file "C:\Computer.cs".



5. Note that at this point, the C: disk (in fact, the current directory of the command prompt) generates a C # source file Computer.cs with the same filename as computer.asmx.



6. Compile the Computer.cs file and enter the following command at the command prompt: C:\>csc/out:computerdll.dll/t:library/r:system.web.services.dll c:\ Computer.cs. Where/out:computerdll.dll is the DLL file to output,/t:library is the output file type,/r:system.web.services.dll is the component to refer to, C:\Computer.cs is the 4th step generated by C # File.



7, at this time, will be in C: Disk under the generation of a file called ComputerDll.dll, to use this file, must be copied to the Teachshow folder under the Bin directory. The default is: C:\Inetpub\wwwroot\TeachShow\bin.



8, create a new Web Forms file named testwsdl.aspx and add a reference to add the ComputerDll.dll file that you just generated as a reference to the project.



9. Write code in the Load event of the Testwsdl.aspx form:

Computernamespace.computer com=new Computernamespace.computer ();

This. Response.Write ("and:" +com). ADD (45,65). ToString () + "
");

This. Response.Write ("Minus:" +com.) Sub (78,900). ToString () + "
");

This. Response.Write ("Multiply:" +com). Multi (43,55). ToString () + "
");

This. Response.Write ("except:" +com). Devide (1000,33). ToString ());

Show Results:

and: 110
Minus: 978
By: 2365
Besides: 30.3030303030303



10, so far, the program is completed.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.