【问题标题】:C# Dynamics Nav WebService unable to get authorizationC# Dynamics Nav WebService 无法获得授权
【发布时间】:2018-02-09 02:55:40
【问题描述】:

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

当我收到以下响应时,我无法对 Web 服务进行身份验证:

  • 响应 {状态代码:401,ReasonPhrase:“未经授权”,版本:1.1,内容:System.Net.Http.StreamContent,标题: { 日期:2017 年 8 月 31 日星期四 08:12:15 GMT 服务器:Microsoft-HTTPAPI/2.0 WWW-认证:协商 内容长度:0 }} System.Net.Http.HttpResponseMessage

我的凭据代码示例是:

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

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

【问题讨论】:

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


    【解决方案1】:

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

    使用您当前的凭据:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      相关资源
      最近更新 更多