我正尝试向客户的Web服务发送请求(我不知道客户端使用的底层平台)。我已经在Visual Studio 2010中使用“添加Web引用”消耗了客户端的WSDL,并生成了我的代理类(名为“ContactService”)。
现在,我需要像下面这样添加一个授权头到我的服务请求中。
Header=Authorization & Value=Basic 12345678901234567890
(上面的“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);
}
如何在服务请求中正确添加授权头?
谢谢!