我正在尝试向客户端的Web服务发出请求(我不知道客户端的底层平台).我使用"添加Web引用"在Visual Studio 2010中使用了客户端的WSDL并生成了我的代理类(称为"ContactService").
我现在需要在我的服务请求中添加如下所示的授权标头.
Header=Authorization & Value=Basic 12345678901234567890
Run Code Online (Sandbox Code Playgroud)
(上面的"123456 ..."值只是占位符)
ContactService service = new ContactService();
//not sure if this is the right way - it's not working
WebClient client = new WebClient();
client.Headers.Add("Authorization", "Basic 12345678901234567890");
service.Credentials = client.Credentials;
int contactKey = null;
try
{
contactKey = service.CreateContact("ABC", emailAddress, firstName, lastName, null);
}
Run Code Online (Sandbox Code Playgroud)
将授权标头添加到服务请求的正确方法是什么?
谢谢!