0

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

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

我的代码;

    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>
4

0 回答 0