9

我正在尝试将 Authentication 标头发送到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!");
        }
    }
}
4

1 回答 1

20

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

关联

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

Michaelis.MockService 是提取的 Web 服务库,您可以在以下位置看到有关如何执行此操作的示例:链接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();
于 2011-02-10T15:56:18.827 回答