当我向导航网络服务发送soap请求时,我收到了一个401错误



我正试图向动态导航web服务发送一个XML soap请求。这是WSDL中的XML。我创建了一个web访问密钥,它是XML的密钥参数中的一个。

<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();

使用NavUserPassword验证时,您需要证书。

请参阅MSDN 上的此处

干杯!

相关内容

  • 没有找到相关文章

最新更新