开发者

create C# website to utilize webservice

开发者 https://www.devze.com 2023-02-04 22:32 出处:网络
I have been trying to create a simple webpage in Visual Studio 2010 that accepts some parameters and calls a webservice and then capture the XML that is returned.When looking into calling webservices

I have been trying to create a simple webpage in Visual Studio 2010 that accepts some parameters and calls a webservice and then capture the XML that is returned. When looking into calling webservices from C# and Visual Studio, I see many examples of creating a proxy server, but I don't have to do that to use the service in a java program. Do I really need to do that for what I'm trying to accomplish?

We have a product we purchased and there is an API service available. This service allows us to pass in an XML request and receive an XML document in return with data specific to the request message.

I have added the service reference to my Solution, now what do I need to do to actually call the service? I also have some instructions that mention that I have t开发者_StackOverflow中文版o bind the connection to the webservice using WSDL in Visual Studio, how do I do that?

Sorry if this is a basic question, but I'm trying to learn a new IDE (Visual Studio), a new language (C#) and a new (to me) technology (webservices) all at the same time and the learning curve of all three is killing me!


When you add a service reference, Visual Studio builds a class for you that acts as a web service proxy. What this means is that you can use that class to call methods on the web service as if they were regular methods of that class, like so:

var service = new AcmeService();
int count = service.CountProductsByCategoryName("underwear");

Of course you can do it the hard way, creating a SOAP-compliant XML, making a HTTP connection, sending the XML as POST data, then parse the response back into XML, extract the return value, and handle SOAP errors while doing all this, but the Service Reference approach is much, much easier.


The same wsdl that you enter in Visual Studio to create a proxy can be used in the APIs that you purchused. You should be able to assign a property or by way of a method provided by the API.

0

精彩评论

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