C#Dynamics Nav WebService无法获得授权

时间:2017-08-31 08:17:58

标签: c# web-services soap-client navision

我正在开发一个从Dynamics Nav调用多种Web服务方法的项目。它使用SOAP请求并发送响应xml来进行调用。

我无法对Web服务进行身份验证,因为我得到以下响应:

  
      
  • response {StatusCode:401,ReasonPhrase:'Unauthorized',Version:1.1,Content:System.Net.Http.StreamContent,Headers:   {   日期:星期四,2017年8月31日08:12:15 GMT   服务器:Microsoft-HTTPAPI / 2.0   WWW-Authenticate:谈判   内容长度:0   System.Net.Http.HttpResponseMessage
  •   

我的凭证代码示例是:

var credentials = Encoding.ASCII.GetBytes(usuarioText + ":" + passText);
client.DefaultRequestHeaders.Authorization = new 
    AuthenticationHeaderValue("Windows", Convert.ToBase64String(credentials));

我需要使用Windows身份验证来调用导航服务,我认为我在发送凭据时做错了...

1 个答案:

答案 0 :(得分:1)

如果服务层配置为使用Windows身份验证,则有两种方法可以针对Dynamics NAV Web Service进行身份验证。

使用您当前的凭据:

// Creates instance of service and sets credentials.
Customer_Service service = new Customer_Service();
service.UseDefaultCredentials = true;

或设置凭据(例如来自Config):

// Creates instance of service and sets credentials.
Customer_Service service = new Customer_Service();
service.UseDefaultCredentials = false;
service.Credentials = new NetworkCredential("username", "password", "domain");

更多信息,请访问MSDN:Walkthrough: Registering and Using a Page Web Service (SOAP)