C# Dynamics Nav WebService 无法获得授权

C# Dynamics Nav WebService unable to get authorization

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

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

  • response {StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Date: Thu, 31 Aug 2017 08:12:15 GMT Server: Microsoft-HTTPAPI/2.0 WWW-Authenticate: Negotiate Content-Length: 0 }} System.Net.Http.HttpResponseMessage

我的凭据代码示例是:

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

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

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

使用您当前的凭据:

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

或设置凭据(例如从配置):

// 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)