开发者

C# WSDL proxy methods

开发者 https://www.devze.com 2023-01-18 10:50 出处:网络
I need to consume a SOAP web service from a C# .Net 4.0 client.I\'ve added the WSDL as a Service Reference in VS 2008 and can now see the XML types as classes so I can construct the SOAP message.

I need to consume a SOAP web service from a C# .Net 4.0 client. I've added the WSDL as a Service Reference in VS 2008 and can now see the XML types as classes so I can construct the SOAP message.

The WSDL Port is defined as an Interface and the two operations defined in the WSDL (UploadMe开发者_JAVA技巧ssage and ValidateMessage) are visible methods.

How do you actually use these methods? I thought the Port would be available as a class so you could directly call the methods and that VS would have created the relevant code for sending the SOAP message, but it looks like you have to write code to go in these methods. Is that correct?

I have googled this but can't find a simple example using .Net 4.0 ;-(


When you add your service using Add Service Reference, you should have a new namespace (which you defined in the Add Service Reference dialog box - bottom left corner).

C# WSDL proxy methods

Inside that namespace, there ought to be a class called something like (yourservicename)Client.

If you can't find it, open up the Service References node in your Visual Studio Solution Explorer, and find the Show All Files button in the Solution Explorer's little toolbar - click on it to see all files.

C# WSDL proxy methods

Under your Service Reference, several nodes deep, you should find a file called Reference.cs which contains the code classes generated from your WSDL.

C# WSDL proxy methods

In that Reference.cs, you should find your client class. This is a regular class, which you can instantiate in your code and call methods on. This will call the web service methods on that remote server you want to connect to.


Typically a Service Reference will create a class called [ServiceName]Client that implements the interface you mentioned.

New it up, then call the operations.

Of far greater importance than getting the client and calling it will be your configuration, which will be dependent on the service. This article will help.

0

精彩评论

暂无评论...
验证码 换一张
取 消