0

我正在尝试将 XML 肥皂请求发送到动态导航 Web 服务。这是来自 WSDL 的 XML。我创建了一个 Web 访问密钥,它是 XML 的 key 参数中的一个。

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:Create xmlns:ns1='urn:microsoft-dynamics-schemas/page/customerws'>
      <ns1:CustomerWS>
        <ns1:Key>+gn8Nu4i7iW7D/g9vCaI8HZE5IEi1NBkTBqDp5QfXe4=</ns1:Key>
        <ns1:Shipping_Advice></ns1:Shipping_Advice>
        <ns1:Shipment_Method_Code></ns1:Shipment_Method_Code>
        <ns1:Shipping_Agent_Code></ns1:Shipping_Agent_Code>
        <ns1:Shipping_Agent_Service_Code></ns1:Shipping_Agent_Service_Code>
        <ns1:Shipping_Time></ns1:Shipping_Time>
        <ns1:Base_Calendar_Code></ns1:Base_Calendar_Code>
        <ns1:Customized_Calendar></ns1:Customized_Calendar>
        <ns1:Currency_Code></ns1:Currency_Code>
        <ns1:Language_Code></ns1:Language_Code>
        <ns1:VAT_Registration_No></ns1:VAT_Registration_No>
      </ns1:CustomerWS>
    </ns1:Create>
  </s11:Body>
</s11:Envelope>

这是用于发送此请求的代码:

Console.WriteLine("We have started");                                    
            string pageName = "http://hrp-dmu.uganda.hrpsolutions.co.ug:9047/DynamicsNAV80/WS/Uganda%20Management%20Institute/Page/CustomerWS";            
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageName);
            req.Method = "POST";
            req.ContentType = "text/xml;charset=UTF-8";
            req.ProtocolVersion = new Version(1, 1);
            req.Headers.Add("SOAPAction", @"urn:microsoftdynamicsschemas/page/customerws:Create");            
            Console.WriteLine("After preparing request object");
            string xmlRequest = GetTextFromXMLFile("E:\\tst3.xml");
            Console.WriteLine("xml request : "+xmlRequest);
            byte[] reqBytes = new UTF8Encoding().GetBytes(xmlRequest);
            req.ContentLength = reqBytes.Length;
            try
            {
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(reqBytes, 0, reqBytes.Length);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("GetRequestStreamException : " + ex.Message);
            }
            HttpWebResponse resp = null;
            try
            {
                resp = (HttpWebResponse)req.GetResponse();
            }
            catch (Exception exc)
            {
                Console.WriteLine("GetResponseException : " + exc.Message);
            }
            string xmlResponse = null;
            if (resp == null)
            {
                Console.WriteLine("Null response");
            }
            else
            {
                using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                {
                    xmlResponse = sr.ReadToEnd();
                }
                Console.WriteLine("The response");
                Console.WriteLine(xmlResponse);
            }
            Console.ReadKey();

4

1 回答 1

0

使用 NavUserPassword 身份验证时,您需要一个证书。

在MSDN上看到这里

干杯!

于 2016-01-08T13:00:16.557 回答