c# - 如何向我的 SOAP 添加 Basic Auth Header?

标签 c# soap basic-authentication soapheader

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

如何将 Auth header 添加到 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 相关,包括用户/密码问题。

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();

关于c# - 如何向我的 SOAP 添加 Basic Auth Header?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4945420/

相关文章:

c# - 使用转换器的数据触发器不起作用

c# - 检查 null 的性能损失

java - 向 SOAP 消息添加 header

java - 使用 WSDL 生成客户端代码后如何摆脱 WSDL 依赖性?

c# - 为什么我的 Http 客户端在我指定凭据时发出 2 个请求?

basic-authentication - 预渲染 basicAuth 配置

java - 通过 HttpClient 连接 Tomcat 管理器

c# - 我如何将此 C# 代码概括为更通用的方法?

c# - Web 引用代理是指定的字段

java - 基于 WSDL 即时创建 Web 服务