Example 31 : Authentication in C#

Printer-friendly version

After generating the code using wsdl.exe, you can call the services using HTTP authentication. This is very simple in .NET and you make use of the NetworkCredential object.

static void Main(string[] args)
{
  ConsignmentSearchServiceService serviceStub = new ConsignmentSearchServiceService();
 
  serviceStub.Url = "http://test1.metapack.com/dm/services/ConsignmentSearchService";
  serviceStub.Credentials = new System.Net.NetworkCredential("userName", "password");
 
  Consignment[] consignments = serviceStub.findConsignmentsByOrderReference("TEST01");
  if (consignments.Length > 0)
  {
    System.Diagnostics.Debug.WriteLine("OK Found consignment " + consignments[0].consignmentCode);
  }
  else
  {
    System.Diagnostics.Debug.WriteLine("No consignments matched" );
  }
}