2017-08-31 59 views
0

我正在開發一個調用Dynamics Nav的多個Web服務方法的項目。它使用SOAP請求併發送響應xml來完成調用。C#動態導航Web服務無法獲得授權

我無法驗證到Web服務,因爲我得到如下回應:

  • 響應{的StatusCode:401,ReasonPhrase: '未授權',版本:1.1,內容:System.Net .Http.StreamContent,頭: { 日期:星期四,2017年8月31日八時12分15秒GMT 服務器:HTTPAPI/2.0 WWW身份驗證:協商 的Content-Length:0 }} System.Net。 Http.HttpResponseMessage

我的憑據代碼示例是:

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

我需要Windows身份驗證調用導航服務,我覺得我做錯事發的證書......

回答

1

如果服務層配置爲使用Windows身份驗證,有兩種方式可以對Dynamics NAV Web Service進行身份驗證。

使用您當前的憑據:

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