【问题标题】:How can I add a Basic Auth Header to my SOAP?如何将基本身份验证标头添加到我的 SOAP?
【发布时间】:2011-02-09 13:22:31
【问题描述】:

我正在尝试将身份验证标头发送到没有的 WSDL 服务 WSDL 上指定的身份验证要求。

如何将 Auth 标头添加到 Web 服务的调用中?

我一直在使用的代码:

using System;
using System.Web.Services.Protocols;

namespace TesteSoap
{           
    class MainClass
    {
        public static void Main (string[] args)
        {

            WSDLService Service = new WSDLService();
            /* How can I add authentication to the call of this webservice ? */
            Service.get();
            Console.WriteLine ("Hello World!");
        }
    }
}

【问题讨论】:

  • 刚刚注意到问题可能是我没有在 WSDL 中请求授权。必须阅读更多内容。

标签: c# soap basic-authentication soapheader


【解决方案1】:

此问题在其他链接中受到质疑,但与 WSDL 相关的方式不同,包括用户/密码问题。

link

它们不是同一个问题,但问题是相关的。

Michaelis.MockService 是提取的 Web 服务库,您可以在 link Mono 项目网站中看到有关如何执行此操作的示例。

Michaelis.MockService service = new Michaelis.MockService();

// Create the network credentials and assign
// them to the service credentials
NetworkCredential netCredential = new NetworkCredential("Inigo.Montoya", "Ykmfptd");
Uri uri = new Uri(service.Url);
ICredentials credentials = netCredential.GetCredential(uri, "Basic");
service.Credentials = credentials;

// Be sure to set PreAuthenticate to true or else
// authentication will not be sent.
service.PreAuthenticate = true;

// Make the web service call.
service.Method();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 2015-03-13
    • 1970-01-01
    相关资源
    最近更新 更多