简体   繁体   English

C#Dynamics Nav WebService无法获得授权

[英]C# Dynamics Nav WebService unable to get authorization

Im developing a project that calls multiple methods of web services from Dynamics Nav. 我正在开发一个从Dynamics Nav调用多种Web服务方法的项目。 It uses a SOAP request and sends an response xml to do the call. 它使用SOAP请求并发送响应xml进行调用。

I'm unable to authenticate to the web service as I get the following response: 当收到以下响应时,我无法通过Web服务进行身份验证:

  • 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 响应{状态代码:401,原因短语:'未经授权',版本:1.1,内容:System.Net.Http.StreamContent,标头:{日期:2017年8月31日星期四08:12:15 GMT服务器:Microsoft-HTTPAPI / 2.0 WWW -验证:协商内容长度:0}} System.Net.Http.HttpResponseMessage

My sample of credentials code is: 我的凭证代码示例是:

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

I need windows authentication for calling the nav service, I think I'm doing something wrong sending the credentials... 我需要Windows身份验证才能调用导航服务,我认为我在发送凭据时做错了...

If the Service Tier is configured to use Windows Authentication, there are two ways to Authentication against Dynamics NAV Web Service. 如果将服务层配置为使用Windows身份验证,则有两种针对Dynamics NAV Web服务进行身份验证的方法。

Using your current Credentials: 使用当前的凭证:

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

Or setting Credentials (eg from Config): 或设置凭据(例如来自Config):

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

More at MSDN: Walkthrough: Registering and Using a Page Web Service (SOAP) MSDN上的更多信息: 演练:注册和使用页面Web服务(SOAP)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM