I m new to web services, and for a client I would like to create DHL package label by a DHL-webservice. Unfortunately, they don't provide code support. So, I need your help...
My code is as below and I get the HttpWebResponse.StatusDescription "OK". However, I don't know how to get the package label URL from the response.
TestIntraship.CreateShipmentDDRequest
createShipmentDDRequest = new
TestIntraship.CreateShipmentDDRequest();
But createShipmentDDRequest returns null when I try to add a shipment order: createShipmentDDRequest.ShipmentOrder[0].SequenceNumber = "1";
Here is the link for the
sample XMLrequest that DHL provided.
I
don't know which approach I should use, and would really appreciate any help.
If you have XMLRequest string, then you can use Webrequest to call your web service as the above you described, and then read the XML response stream using XmlTextReader whose Read() method to progress through the nodes. Here is a article about it.
Thank you for your response. I tried the link and was able to retrieve a response, but the response is not what I am supposed to get. I noticed the DHL web service has an endpoint based on wsdl. I followed your post at
http://forums.asp.net/t/1683966.aspx/1 and I added the wdsl as service reference which was fine. When I try to call the class and assign a value as below, it throws a System.NullReferenceException . What
am I possibly doing wrong? Thanks.
This error illustrates that object reference not set to an instance of an object, see the above listed code, if CreateShipmentDDRequest is a class and it is a member of createShipmentDDRequest1, you need to make sure to create an instance of CreateShipmentDDRequest.
It is very strange, you can set a break point at the first line of your method and debug it step by step, check which line throws this exception, you can also step into your web service to debug, using Debug->Attach to process to attach to the aspnet_wp
or w3wp.exe processess.
I have found a sample code from DHL developer forum which creates a Proxy class through wsdl.exe , but I can't find it in SDK bin folder. How can I create the Proxy class without the wsdl.exe ? I had already added wsdl link as web reference. The sample code
from the forum is below. Thanks again and I hope what I am asking makes sense.
B10
Member
6 Points
15 Posts
Creating DHL package label through a web service...
Apr 11, 2012 11:04 AM|LINK
Hello,
I m new to web services, and for a client I would like to create DHL package label by a DHL-webservice. Unfortunately, they don't provide code support. So, I need your help...
My code is as below and I get the HttpWebResponse.StatusDescription "OK". However, I don't know how to get the package label URL from the response.
WebRequest webRequest = WebRequest.Create(http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl);
HttpWebRequest hwRequest = (HttpWebRequest)webRequest;
hwRequest.Method = "POST";
hwRequest.ContentType = "text/xml; charset=utf-8";
hwRequest.Headers.Add("SOAPAction: http://tempuri.org/");
hwRequest.ProtocolVersion = HttpVersion.Version11;
hwRequest.Credentials = CredentialCache.DefaultCredentials;
string xmlRequest = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
"<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:cis='http://dhl.de/webservice/cisbase' xmlns:de='http://de.ws.intraship'>" +
"<cis:user>Test</cis:user>" +
"<cis:signature>Pass</cis:signature>" +
"<cis:type>0</cis:type>" +
"</cis:Authentification>" +
"</soap:Header>" +
"<soap:Body>" +
"<de:CreateShipmentDDRequest>" +
.... +
"<ShipmentOrder>" +
"<LabelResponseType>URL</LabelResponseType>" +
"</ShipmentOrder>" +
"</de:CreateShipmentDDRequest>" +
"</soap:Body>" +
"</soap:Envelope>";
XmlDocument soapXml = new XmlDocument();
soapXml.LoadXml(xmlRequest);
using (Stream stream = hwRequest.GetRequestStream())
{
soapXml.Save(stream);
}
HttpWebResponse wr = (HttpWebResponse)hwRequest.GetResponse();
StreamReader srd = new StreamReader(wr.GetResponseStream());
And I'm stuck here... Thank you in advance
HttpWebResponse soap webservice
B10
Member
6 Points
15 Posts
Re: Creating DHL package label through a web service...
Apr 12, 2012 07:18 AM|LINK
Another approach I tried was adding the wdsl as web reference (TestIntraship):
TestIntraship.AuthentificationType auth = new TestIntraship.AuthentificationType();
auth.user = "user";
auth.signature = "signiture";
auth.accountNumber = "5000000000 01";
auth.type = "0";
TestIntraship.CreateShipmentDDRequest createShipmentDDRequest = new TestIntraship.CreateShipmentDDRequest();
But createShipmentDDRequest returns null when I try to add a shipment order:
createShipmentDDRequest.ShipmentOrder[0].SequenceNumber = "1";
Here is the link for the sample XMLrequest that DHL provided.
I don't know which approach I should use, and would really appreciate any help.
HttpWebResponse soap webservice
B10
Member
6 Points
15 Posts
Re: Creating DHL package label through a web service...
Apr 12, 2012 07:39 PM|LINK
No one?
Peter pi - M...
Star
12871 Points
1786 Posts
Re: Creating DHL package label through a web service...
Apr 13, 2012 02:02 AM|LINK
If you have XMLRequest string, then you can use Webrequest to call your web service as the above you described, and then read the XML response stream using XmlTextReader whose Read() method to progress through the nodes. Here is a article about it.
http://www.noboxsolutions.com/xmltextreader_stream.aspx
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
B10
Member
6 Points
15 Posts
Re: Creating DHL package label through a web service...
Apr 14, 2012 08:55 PM|LINK
Thank you for your response. I tried the link and was able to retrieve a response, but the response is not what I am supposed to get. I noticed the DHL web service has an endpoint based on wsdl. I followed your post at http://forums.asp.net/t/1683966.aspx/1 and I added the wdsl as service reference which was fine. When I try to call the class and assign a value as below, it throws a System.NullReferenceException . What am I possibly doing wrong? Thanks.
WSDL : http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl
Endpoint : http://test-intraship.dhl.com/ws/1_0/de/ISService
DHL.AuthentificationType auth = new DHL.AuthentificationType();
auth.user = "TestKND";
auth.signature = "DHLdhl123";
auth.type = "0";
DHL.createShipmentDDRequest1 createShipmentDDRequest1 = new DHL.createShipmentDDRequest1();
createShipmentDDRequest1.CreateShipmentDDRequest.ShipmentOrder[0].SequenceNumber = "1";
Peter pi - M...
Star
12871 Points
1786 Posts
Re: Creating DHL package label through a web service...
Apr 16, 2012 07:08 AM|LINK
This error illustrates that object reference not set to an instance of an object, see the above listed code, if CreateShipmentDDRequest is a class and it is a member of createShipmentDDRequest1, you need to make sure to create an instance of CreateShipmentDDRequest.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
B10
Member
6 Points
15 Posts
Re: Creating DHL package label through a web service...
Apr 16, 2012 09:31 AM|LINK
I create the instance of CreateShipmentDDRequest as below, but still getting an "object reference not set to an instance of an object".
DHL.CreateShipmentDDRequest createShipmentDDRequest = new DHL.CreateShipmentDDRequest();
createShipmentDDRequest.ShipmentOrder[0].SequenceNumber = "1";
Peter pi - M...
Star
12871 Points
1786 Posts
Re: Creating DHL package label through a web service...
Apr 16, 2012 09:48 AM|LINK
It is very strange, you can set a break point at the first line of your method and debug it step by step, check which line throws this exception, you can also step into your web service to debug, using Debug->Attach to process to attach to the aspnet_wp or w3wp.exe processess.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
B10
Member
6 Points
15 Posts
Re: Creating DHL package label through a web service...
Apr 27, 2012 02:47 PM|LINK
Hi Peter,
I have found a sample code from DHL developer forum which creates a Proxy class through wsdl.exe , but I can't find it in SDK bin folder. How can I create the Proxy class without the wsdl.exe ? I had already added wsdl link as web reference. The sample code from the forum is below. Thanks again and I hope what I am asking makes sense.
namespace dhlVIAsoapconnect {
class Program {
static void Main(string[] args) {
Console.WriteLine("DHL Intraship SOAP Connect");
Console.WriteLine();
ISService_1_0_de dhlIS = new ISService_1_0_de();
Console.WriteLine("IService Object created!");
AuthentificationType autype = new AuthentificationType();
autype.user = "user";
autype.type = "0";
autype.signature = "pass";
dhlIS.Authentification = autype;
.........
SERGIYKO5
Member
4 Points
2 Posts
Re: Creating DHL package label through a web service...
May 08, 2012 01:18 PM|LINK
May be :
TestIntraship.CreateShipmentDDRequest createShipmentDDRequest = new TestIntraship.CreateShipmentDDRequest();
createShipmentDDRequest.ShipmentOrder = new ShipmentOrderCollection() // add something like this...(?)
createShipmentDDRequest.ShipmentOrder[0]=new ShipmentOrder() // add something like this...(?)
//or this :
createShipmentDDRequest.ShipmentOrder.Add()
createShipmentDDRequest.ShipmentOrder[0].SequenceNumber = "1";
HttpWebResponse soap webservice