Getting started with .NET

Printer-friendly version

Microsoft has done a sterling job with webservices. The tools, however, are somewhat cumbersome. The WSDL->C# code generator, wsdl.exe, produces code that is hardly developer-friendly. Moreover, the code does not support HTTP/1.0 by default. This article describes how to integrate with Delivery Manager.

Is there a quick way to get started?

Yes. The C# client code is attached to the bottom of this article. It contains all services and all types, with all of the above modifications made for you. Furthermore, it also includes a wrapper class, DeliveryManagerClient, to make life little easier. Make sure you download the appropriate one (for version DM API 2.x or DM API 3.x).

The source code provided here means you don't have to worry about generating the code yourself, and it also takes care of the authentication.

One of the key problems of Microsoft's wsdl.exe is that it produces code that is not HTTP 1.0 compliant. It results in the integrator getting the error "The request failed with HTTP status 505: HTTP Version Not Supported". To fix this, we need to override the SoapHttpClientProtocol.GetWebRequest method to fix the protocol version.

And we need to do this for each of the services we use. e.g. Both ConsignmentServiceService and ConsignmentSearchServiceService need to be overridden before they can be used.

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
  System.Net.HttpWebRequest req;
  req = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
  req.ProtocolVersion = System.Net.HttpVersion.Version10;
  return req;
}

 

For other languages, such as VB.NET, I recommend you create a new C# Class Library, and drag the source file into the project. Ensure there's a reference to System.Web.Services, and compile it. You can then just add the DLL as a reference in your VB.NET application

You might want to consider looking at Example 33 to disover how to generate your own C# code from the WSDLs. And to cover things like authentication, have a look at Example 31.

 

 

AttachmentSize
DeliveryManagerClient_2_1.zip17.68 KB
DeliveryManagerClient3.zip22.86 KB