简体   繁体   中英

wsdl to asmx webservice HELP!

I've searched for this problem and I always get stuck on the step after you've generated a .cs file using the command "wsdl.exe myfile.wsdl /l:CS /ServerInterface" in the Microsoft Visual Studio prompt. I've imported the .cs file into a Visual Studio web service project. and It have a service1.asmx.cs file I dont know what to do with.

I'm a complete newbie when it comes to .NET, C#, Visual Studio and Web Service so a step to step guide would be awesome!

Forgo the command-line wsdl.exe utility - it's much easier in Visual Studio itself. If you're using VS 2008 or later, right-click on your project, select Add Service Reference and point it to the WSDL on the server you'll be connecting to (eg http://www.blahblah.com/service.asmx?WSDL ) and it will generate the proxy classes and connection parameters in an app.config file.

From where you are, instantiate an object of the proxy class it generated (make sure the namespace it generated is included with a using statement) and make sure it is bound to an endpoint:

BasicHttpBinding binding =
    new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.MaxReceivedMessageSize = int.MaxValue;
EndpointAddress address =
    new EndpointAddress("http://webservices.blahblah.com/service.asmx");
MyService service = new MyServiceClient(binding, address);

and then invoke the remote methods on it:

try
{
    service.DoSomething("someParameter");
    if (service.GetSomeStatus())
    {
    }
}
finally
{
    (service as IDisposable).Dispose();
}

For VS 2005 or earlier, use Add Web Reference and the rest of the procedure is similar.

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