项目调用web服务需要携带用户名,密码,写法如下,还未验证,欢迎留言指正。
方式一:
WebService.Service s = new WebService.Service();
s.Url = "xxxxxx";
s.Credentials = new NetworkCredential(objects[0].ToString(), objects[1].ToString());//添加验证信息
res = s.call("1", "2");//调用接口方法
方式二:
1.引入Nuget包:
Microsoft.Web.Services3
2.web服务继承类改为
Microsoft.Web.Services3.WebServicesClientProtocol
public partial class Service : Microsoft.Web.Services3.WebServicesClientProtocol
WebService.WebService service = new WebService.WebService();
service.RequestSoapContext.Security.Tokens.Add(new UsernameToken(username, pwd, PasswordOption.SendPlainText));
result = service.Server(param1, param2);