我正在尝试将身份验证 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 相关,包括用户/密码问题。
它们不是同一个问题,但问题是相关的。
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/