首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DHL CreateShipmentOrder XML

DHL CreateShipmentOrder XML
EN

Stack Overflow用户
提问于 2022-01-07 12:40:50
回答 1查看 424关注 0票数 2

我正在尝试集成DHL CreateShipmentOrder API。当我用Soap程序发送DHL准备的文档时,它正确地工作。我的代码和返回的结果如下。当我联系DHL时,我无法得到结果。你能帮我吗?

我正在尝试集成DHL CreateShipmentOrder API。当我用Soap程序发送DHL准备的文档时,它正确地工作。我的代码和返回的结果如下。当我联系DHL时,我无法得到结果。你能帮我吗?

我的守则;

代码语言:javascript
复制
    public static void Main()
    {
            // Create Web request to get title elements
            var serviceUrl = "https://cig.dhl.de/services/production/soap";
            HttpWebResponse response = null;
            try
            {
                   String sPayload = String.Format(@"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:cis='http://dhl.de/webservice/cisbase' xmlns:ns='http://dhl.de/webservices/businesscustomershipping/3.0'>
                   <soapenv:Header>
                      <cis:Authentification>
                         <cis:user>*****</cis:user>
                         <cis:signature>*******</cis:signature>
                      </cis:Authentification>
                   </soapenv:Header>                   
                   <soapenv:Body>
                      <ns:CreateShipmentOrderRequest>
                         <ns:Version>
                            <majorRelease>3</majorRelease>
                            <minorRelease>1</minorRelease>
                         </ns:Version>
                         <ShipmentOrder>
                            <sequenceNumber/>
                            <Shipment>
                               <ShipmentDetails>
                                  <product>V01PAK</product>
                                  <cis:accountNumber>********</cis:accountNumber>
                                  <customerReference>Ref. 123456</customerReference>
                                  <shipmentDate>2022-01-06</shipmentDate>
                                  <ShipmentItem>
                                     <weightInKG>5</weightInKG>
                                     <lengthInCM>60</lengthInCM>
                                     <widthInCM>30</widthInCM>
                                     <heightInCM>15</heightInCM>
                                  </ShipmentItem>
                                  <Notification>                                     <recipientEmailAddress>empfaenger@test.de</recipientEmailAddress>
                                  </Notification>
                               </ShipmentDetails>
                               <Shipper>
                                  <Name>
                                     <cis:name1>Absender Zeile 1</cis:name1>
                                     <cis:name2>Absender Zeile 2</cis:name2>
                                     <cis:name3>Absender Zeile 3</cis:name3>
                                  </Name>
                                  <Address>
                                     <cis:streetName>Vegesacker Heerstr.111</cis:streetName>
                                     <cis:zip>28757</cis:zip>
                                     <cis:city>Bremen</cis:city>
                                     <cis:Origin>
                                        <cis:country/>
                                        <cis:countryISOCode>DE</cis:countryISOCode>
                                     </cis:Origin>
                                  </Address>
                                  <Communication>
                                     <!--Optional:-->
                                     <cis:phone>+49421987654321</cis:phone>
                                     <cis:email>absender@test.de</cis:email>
                                     <!--Optional:-->
                                     <cis:contactPerson>Kontaktperson Absender</cis:contactPerson>
                                  </Communication>
                               </Shipper>
                               <Receiver>
                                  <cis:name1>Empfänger Zeile 1</cis:name1>
                                  <Address>
                                     <cis:name2>Empfänger Zeile 2</cis:name2>
                                     <cis:name3>Empfänger Zeile 3</cis:name3>
                                     <cis:streetName>An der Weide 50a</cis:streetName>
                                     <cis:zip>28195</cis:zip>
                                     <cis:city>Bremen</cis:city>
                                     <cis:Origin>
                                        <cis:country/>
                                        <cis:countryISOCode>DE</cis:countryISOCode>
                                     </cis:Origin>
                                  </Address>
                                  <Communication>
                                     <cis:phone>+49421123456789</cis:phone>
                                     <cis:email>empfaenger@test.de</cis:email>
                                     <cis:contactPerson>Kontaktperson Empfänger</cis:contactPerson>
                                  </Communication>
                               </Receiver>
                            </Shipment>
                            <PrintOnlyIfCodeable active='1'/>
                         </ShipmentOrder>
                         <labelResponseType>URL</labelResponseType>         
                         <combinedPrinting>0</combinedPrinting>
                      </ns:CreateShipmentOrderRequest>
                   </soapenv:Body>
                </soapenv:Envelope>");
                
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl) as HttpWebRequest;
                webRequest.ContentType = "text/xml;charset=utf-8";
                webRequest.Headers["Authorization"] = "Basic " +  Convert.ToBase64String(Encoding.ASCII.GetBytes("******:*****"));              
                webRequest.Method = "POST";             
                
                using (var sw = new StreamWriter(webRequest.GetRequestStream()))
                {
                    sw.Write(sPayload);
                    sw.Close();
                }
                response = (HttpWebResponse) webRequest.GetResponse();
            }
            catch (WebException ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
            finally
            {
                if (response != null)
                    Console.WriteLine("Http status = " + response.StatusCode + " - " + response.StatusDescription);
            }       
            if( response != null && response.StatusDescription == "OK" ) {
                Console.WriteLine("Successfull");
            }
            Console.WriteLine(DateTime.Now.ToString());
    }

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Client</faultcode>
            <faultstring>SECURITY_VIOLATION</faultstring>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>
EN

回答 1

Stack Overflow用户

发布于 2022-07-18 07:19:23

为了与DHL通信,必须使用DHL WSDL文件和访问。(在https://developer.dhl.de/下载)

本杰明·穆勒在下面的链接中给出了你的问题的答案。最好使用来自DHL的最新WSDL,仍然需要调整一些对象(实际上只有名称)。

Java WSDL DHL Classes

必须使用下一行下面的两行,否则身份验证将无法工作。

//覆盖BasicAuth用户名和密码

这是DHL不拒绝"SECURITY_VIOLATION“请求的唯一方法。所有其他方式都未经DHL批准并导致错误消息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70621424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档