Third, the agent class

Source: Internet
Author: User

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

You can access the Web service just as you would access a COM object. To access the Web service, you need to create a proxy class from the WSDL document of the Web service on the local computer.. NET provides a tool called 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 and write the following code:

[WebMethod (description= "for additive operation", Enablesession=false)]

public int Add (int a,int b)

{

return a+b;

}

[WebMethod (description= "for subtraction operation", Enablesession=false)]

public int Sub (int a,int b)

{

return a+b;

}

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

public int Multi (int a,int b)

{

return a*b;

}

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

public double devide (int a,int b)

{

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

3, according to F5 compile the entire 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: Wsdl/out:computer.cs http://localhost/TeachShow/Charpter8/FirstAndUse/Computer.asmx/n: Computernamespace, where/out:computer.cs is the CS file to output,/n:computernamespace is the custom namespace. Tips 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 in the D: Disk (actually is the command prompt current directory) to generate a and computer.asmx the same file name of C # source file Computer.cs.

6. Compile the Computer.cs file and enter the following command at the command prompt: Csc/out:computerdll.dll/t:library/r:system.web.services.dll 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 be referenced, and Computer.cs is the C # file generated in the 4th step.

7, at this time, will be in the D: disk to generate a file called ComputerDll.dll, to use this file, you must copy to the Teachshow folder under the Bin directory.

8. Create a new Web Form file named Testwsdl.aspx and add a reference to add the ComputerDll.dll file 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 ());

Note: Personal opinion:

There are several ways to call WebService:

1. How to add Web references

2. Generate the proxy class and invoke the methods in the proxy class

3. The proxy class is regenerated into a DLL, the last DLL reference is added, and the method in the DLL is finally called

Third, the agent class

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.