C# 如何将基本身份验证头添加到SOAP中?
我正试图通过C# 如何将基本身份验证头添加到SOAP中?,c#,soap,basic-authentication,soapheader,C#,Soap,Basic Authentication,Soapheader,我正试图通过WSDL服务发送一个身份验证头,该服务没有 WSDL上指定的身份验证要求 如何将Auth头添加到web服务的调用中 我一直使用的代码: using System; using System.Web.Services.Protocols; namespace TesteSoap { class MainClass { public static void Main (string[] args) {
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相关的方式不同,包括用户/密码问题 它们不是同一个问题,但问题是相关的 MockService是提取的Webservice库,您可以在Mono project网站中看到一个如何执行此操作的示例
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();
注意到问题可能是我没有在WSDL中请求授权。我必须读更多关于这方面的文章。