【问题标题】:I am getting a 401 error when I am sending a soap request to a nav web service向导航 Web 服务发送肥皂请求时收到 401 错误
【发布时间】:2016-04-11 23:34:33
【问题描述】:

我正在尝试向动态导航 Web 服务发送 XML 肥皂请求。这是来自 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();

【问题讨论】:

  • 401 错误表示身份验证问题。您在这里使用哪种身份验证?
  • 欢迎使用 Stack Overflow(也称为 SO)!这是一个很好的帖子。我确实编辑了一些代码块,我删除了&lt;code&gt; 标签,这些标签在您使用降价时是不必要的,并添加了额外的空白。我唯一做的另一件事是更改 wsdl 和 xml 的大小写,它们是首字母缩略词,应该是大写的。感谢您的帖子,希望您能得到答案!
  • 我正在使用 navuserpassword 进行身份验证。并且正在使用生成的访问代码进行身份验证。

标签: web-services soap http-status-code-401 dynamics-nav-2015


【解决方案1】:

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

见这里MSDN

干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 2016-10-07
    相关资源
    最近更新 更多