简体   繁体   中英

Generating a Web service proxy from a WSDL C#

I am working with Fedex webservice. They did not provide a webservice URL like http://hostServer/WebserviceRoot/WebServiceName.asmx . Rather they provided a .wsdl file.

Please guide me in generating the web service proxy classes from the .wsdl file and adding a web service reference to my project.

I know to generate the proxy from wsdl like

wsdl /l:cs /protocol:SOAP /o:MyProxy.cs mywsdl.wsdl

but I want to know what it does. It may create the proxy class but how can I add the web service reference to my project?

If you are creating the proxy classes manually, you need only add them to your project. The Add Web Reference mechanism in Visual Studio is used to automate this process and add the types in.

The wsdl executable will read the WSDL file that you've downloaded ("mywsdl.wsdl"), and generate the proxy code, in your example in the C# language (in "MyProxy.cs"). You can add "MyProxy.cs" to your project and start instantiating instances of the generated client in your project.

use the wsdl.exe command from the visual studio command prompt.

ex:

WSDL c:/myfile.wsdl

There are usually two ways to deal with web services. One, like you mentioned, use a web service URL../service.asmx. This way you just need to use "Add web reference" in the visual studio project and you are always connected to the live web service. This is much easier, the downside is if the web service decides to change something, you need to change your reference as well. Recompile the project and redeploy.

When you keep a local copy of the wsdl file, if they introduce a mandatory field in the live WSDL, you are still protected as long as the underlying code base still works with it. If you are generating the proxy.cs class on your own, as in the accepted answer, it just works like adding it through visual studio except that you have to manually add the class to the project.

Also, i believe you can get the whole web service url from <soap:address location="http://testsite.com/test.asmx" /> in the WSDL file. Usually it is not a good practice to use a local WSDL file if your intention is to keep up with any changes. I doubt you will have that problem since it is a fedex web service, probably has stood through the test of time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM