Я создал запрос на отправку в DHL для метки отгрузки в виде изображения / pdf, но я получаю 500 не найденных ошибок, но когда я делаю запрос на оценку, это работает, следуя моему коду, я добавил заголовок безопасности мыла, а затем такженеавторизованный запрос прошел через документацию по dhl api, но не получил ответа
public class SoapSecurityHeader : MessageHeader
{
private readonly string _password, _username, _nonce;
private readonly DateTime _createdDate;
public SoapSecurityHeader(string id, string username, string password, string nonce)
{
_password = password;
_username = username;
_nonce = nonce;
_createdDate = DateTime.Now;
this.Id = id;
}
public string Id { get; set; }
public override string Name
{
get { return "Security"; }
}
public override string Namespace
{
get { return "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; }
}
protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteStartElement("wsse", Name, Namespace);
writer.WriteXmlnsAttribute("wsse", Namespace);
}
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteStartElement("wsse", "UsernameToken", Namespace);
writer.WriteAttributeString("Id", "UsernameToken-10");
writer.WriteAttributeString("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
writer.WriteStartElement("wsse", "Username", Namespace);
writer.WriteValue(_username);
writer.WriteEndElement();
writer.WriteStartElement("wsse", "Password", Namespace);
writer.WriteAttributeString("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
writer.WriteValue(_password);
writer.WriteEndElement();
writer.WriteStartElement("wsse", "Nonce", Namespace);
writer.WriteAttributeString("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
writer.WriteValue(_nonce);
writer.WriteEndElement();
writer.WriteStartElement("wsse", "Created", Namespace);
writer.WriteValue(_createdDate.ToString("yyyy-MM-ddThh:mm:ss"));
writer.WriteEndElement();
writer.WriteEndElement();
}
}
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
static void Main(string[] args)
{
string usn = "XXXXXX";
string pwd = "XXXXXX";
SoapSecurityHeader soapSecurityHeader = new SoapSecurityHeader(Guid.NewGuid().ToString(), usn , pwd , Base64Encode(Guid.NewGuid().ToString("N")));
string xmlBody = @"<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:glob='http://scxgxtt.phx-dc.dhl.com/glDHLExpressLabel/providers/globalLabel'>";
xmlBody += soapSecurityHeader.ToString();
xmlBody += @" <soap:Body> " +
"<shipreq:ShipmentRequest>" +
"<RequestedShipment>" +
"<ShipmentInfo>" +
"<DropOffType>REQUEST_COURIER</DropOffType> <!--Mandatory-->" +
"<ServiceType>U</ServiceType> <!--Mandatory-->" +
"<Account> XXXXXXXXX</Account> <!--Mandatory-->" +
"<Currency>EUR</Currency> <!--Mandatory-->" +
"<UnitOfMeasurement>SI</UnitOfMeasurement> <!--Mandatory-->" +
"<PackagesCount>1</PackagesCount> <!--Optional-->" +
"<LabelType>PDF</LabelType> <!--Optional-->" +
"<LabelTemplate>ECOM26_84_001</LabelTemplate> <!--Optional-->" +
"</ShipmentInfo>" +
"<ShipTimestamp>2010-10-29T09:30:47GMT+01:00</ShipTimestamp> <!--Mandatory-->" +
"<PickupLocationCloseTime>16:12</PickupLocationCloseTime> <!--Optional-->" +
"<SpecialPickupInstruction>fragile items</SpecialPickupInstruction> <!--Optional-->" +
"<PickupLocation>west wing 3rd Floor</PickupLocation> <!--Optional-->" +
"<PaymentInfo>DDP</PaymentInfo> <!--Mandatory-->" +
"<InternationalDetail>" +
"<Commodities>" +
"<NumberOfPieces>1</NumberOfPieces> <!--Mandatory-->" +
"<Description>ppps sd</Description> <!--Mandatory-->" +
"<CountryOfManufacture>CZ</CountryOfManufacture> <!--Optional-->" +
"<Quantity>1</Quantity> <!--Optional-->" +
"<UnitPrice>10</UnitPrice> <!--Optional-->" +
"<CustomsValue>1</CustomsValue> <!--Optional-->" +
"</Commodities>" +
"<Content>NON_DOCUMENTS</Content> <!--Mandatory-->" +
"</InternationalDetail>" +
"<Ship>" +
"<Shipper>" +
"<Contact>" +
"<PersonName>John Smith</PersonName> <!--Mandatory-->" +
"<CompanyName>DHL</CompanyName> <!--Mandatory-->" +
"<PhoneNumber>003932423423</PhoneNumber> <!--Mandatory-->" +
"<EmailAddress>John.Smith@dhl.com</EmailAddress> <!--Optional-->" +
"</Contact>" +
"<Address>" +
"<StreetLines>V Parku 2308/10</StreetLines> <!--Mandatory-->" +
"<City>Prague</City> <!--Mandatory-->" +
"<PostalCode>14800</PostalCode> <!--Mandatory-->" +
"<CountryCode>CZ</CountryCode> <!--Mandatory-->" +
"</Address>" +
"</Shipper>" +
"<Recipient>" +
"<Contact>" +
"<PersonName>Jane Smith</PersonName> <!--Mandatory-->" +
"<CompanyName>Deutsche Post DHL</CompanyName> <!--Mandatory-->" +
"<PhoneNumber>004922832432423</PhoneNumber> <!--Mandatory-->" +
"<EmailAddress>Jane.Smith@dhl.de</EmailAddress> <!--Optional-->" +
"</Contact>" +
"<Address>" +
"<StreetLines>Via Felice Matteucci 2</StreetLines> <!--Mandatory-->" +
"<City>Firenze</City> <!--Mandatory-->" +
"<PostalCode>50127</PostalCode> <!--Mandatory-->" +
"<CountryCode>IT</CountryCode> <!--Mandatory-->" +
"</Address>" +
"</Recipient>" +
"</Ship>" +
"<Packages>" +
"<RequestedPackages number='1'> <!--Mandatory-->" +
"<InsuredValue>10</InsuredValue> <!--Optional-->" +
"<Weight>9.0</Weight> <!--Mandatory-->" +
"<Dimensions>" +
"<Length>46</Length> <!--Mandatory-->" +
"<Width>34</Width> <!--Mandatory-->" +
"<Height>31</Height> <!--Mandatory-->" +
"</Dimensions>" +
"<CustomerReferences>TEST CZ-IT</CustomerReferences> <!--Mandatory-->" +
"</RequestedPackages>" +
"</Packages>" +
"</RequestedShipment>" +
"</shipreq:ShipmentRequest>" +
"</soap:Body>" +
"</soap:Envelope>";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wsbexpress.dhl.com/sndpt/expressRateBook");
byte[] bytes;
bytes = System.Text.Encoding.ASCII.GetBytes(xmlBody);
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
HttpWebResponse response;
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
//return responseStr;
}
}
я что-то не так делаю в коде?