Consuming Webservice in C# - XML request / XML Response

  • Thread starter Thread starter Mick1080
  • Start date Start date
M

Mick1080

Guest
Dear All,

I am new and a complete dummy in web service stuff. What I would like to achieve is to call a WSDL webservice in C# (windows application). I know that in VS2010 I have to create a web service reference using the webservice wsdl but after that I am quite lost. I have a WSDL of DHL ( https://wsbuat.dhl.com:8300/amer/GEeuExpressRateBook?WSDL ) which have different functions like createshipmentrequest, deleteshipmentrequest and getraterequest. This is the last one I would like to use for my first testing. the XML request consist apprently of different doctype which may content simple of complex elements. Can someone guide me how to :

1) built my request

2) send the request to the webservice

3) get the response.

here a sample of what I was trying but it is not working of course :-(


using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void submitbtn_Click(object sender, EventArgs e)
{
this.output.Text = "Querying the webservice...";
Soapdemo1.ServiceReference1.amerGEeuExpressRateBookClient soap = new Soapdemo1.ServiceReference1.amerGEeuExpressRateBookClient();

soap.ClientCredentials.UserName.UserName = "xxxx";
soap.ClientCredentials.UserName.Password = "xxxxx";

// define request as to be the whole request message

Soapdemo1.ServiceReference1.getRateRequestRequest request = new Soapdemo1.ServiceReference1.getRateRequestRequest();

// define de client details structure

Soapdemo1.ServiceReference1.docTypeRef_ClientDetailType3 clientdetail = new Soapdemo1.ServiceReference1.docTypeRef_ClientDetailType3();
clientdetail.plant = "test";
clientdetail.sso = "test";
request.ClientDetail = clientdetail;

// define de requestedshipment structure

Soapdemo1.ServiceReference1.docTypeRef_RequestedShipmentType2 requestedshipment = new Soapdemo1.ServiceReference1.docTypeRef_RequestedShipmentType2();

requestedshipment.DropOffType = 0;
requestedshipment.NextBusinessDay = 0;

// definte de ship structure of requestedshipment

Soapdemo1.ServiceReference1.docTypeRef_ShipType2 ship = new Soapdemo1.ServiceReference1.docTypeRef_ShipType2();
Soapdemo1.ServiceReference1.docTypeRef_AddressType2 shipper = new Soapdemo1.ServiceReference1.docTypeRef_AddressType2();
Soapdemo1.ServiceReference1.docTypeRef_AddressType2 recipient = new Soapdemo1.ServiceReference1.docTypeRef_AddressType2();

shipper.City = "";
shipper.CountryCode = "";
shipper.PostalCode = "";
shipper.StreetLines = "";
shipper.StreetLines2 = "";
shipper.StreetLines3 = "";
shipper.StreetName = "";
shipper.StreetNumber = "";
ship.Shipper = shipper;

recipient.City = "";
recipient.CountryCode = "";
recipient.PostalCode = "";
recipient.StreetLines = "";
recipient.StreetLines2 = "";
recipient.StreetLines3 = "";
recipient.StreetName = "";
recipient.StreetNumber = "";
ship.Recipient = recipient;

requestedshipment.Ship = ship;

//define package

Soapdemo1.ServiceReference1.docTypeRef_PackagesType packages = new Soapdemo1.ServiceReference1.docTypeRef_PackagesType();
Soapdemo1.ServiceReference1.docTypeRef_RequestedPackagesType2 requestedpackages = new Soapdemo1.ServiceReference1.docTypeRef_RequestedPackagesType2();
Soapdemo1.ServiceReference1.docTypeRef_WeightType weight = new Soapdemo1.ServiceReference1.docTypeRef_WeightType();
Soapdemo1.ServiceReference1.docTypeRef_DimensionsType2 dimensions = new Soapdemo1.ServiceReference1.docTypeRef_DimensionsType2();

weight.Value = 10;

dimensions.Height = 10;
dimensions.Length = 10;
dimensions.Width = 10;

requestedpackages.number = 1;
requestedshipment.ShipTimestamp = "";
requestedshipment.UnitOfMeasurement = 0;
requestedshipment.Content = 0;
requestedshipment.Account = "123543432";

request.RequestedShipment = requestedshipment;

// Soapdemo1.ServiceReference1.getRateRequestResponse response = new Soapdemo1.ServiceReference1.getRateRequestResponse();
Soapdemo1.ServiceReference1.getRateRequestResponse reponse = new Soapdemo1.ServiceReference1.getRateRequestResponse();

try
{


reponse = soap.getRateRequest(request.ClientDetail, request.RequestedShipment);

this.output.Text = "incident created " + reponse + "\n";
}
catch (Exception error)
{
this.output.Text = "Error in request : " + request + "\n";
}


}
}
}

Can someone help me ?

Thanks

Continue reading...
 
Back
Top