President Camacho
President Camacho

Reputation: 1910

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!

Upvotes: 0

Views: 901

Answers (1)

Jesse C. Slicer
Jesse C. Slicer

Reputation: 20157

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 (e.g. 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.

Upvotes: 1

Related Questions