C# Web服务用户身份验证
我正在尝试开发具有用户授权的web服务客户端。 我已经向我的项目添加了服务引用,但现在我坚持使用用户身份验证, 我得到的只是:C# Web服务用户身份验证,c#,security,authorization,webservice-client,C#,Security,Authorization,Webservice Client,我正在尝试开发具有用户授权的web服务客户端。 我已经向我的项目添加了服务引用,但现在我坚持使用用户身份验证, 我得到的只是: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 这就是我如何称呼我的Web服务: BasicHttpBinding a = new BasicHttpBinding("MyWebService1"); a.Security.Mode = BasicHttpS
The HTTP request is unauthorized with client authentication scheme 'Anonymous'.
这就是我如何称呼我的Web服务:
BasicHttpBinding a = new BasicHttpBinding("MyWebService1");
a.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
a.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
MyWebService1Client mySeviceClient= new MyWebService1Client();
mySeviceClient= new MyWebService1Client(a, mySeviceClient.Endpoint.Address);
mySeviceClient.ClientCredentials.UserName.UserName = "test2";
mySeviceClient.ClientCredentials.UserName.Password = "password";
try
{
mySeviceClient.Open();
MyWebService1 myWebService= mySeviceClient;
myRequest req = new myRequest(1234, "Test");
myResponse res = myWebService.getMyData(req);
mySeviceClient.Close();
}
catch (AddressAccessDeniedException adExc)
{
Console.WriteLine(adExc.Message);
Console.ReadLine();
}
catch (System.Exception exc)
{
Console.WriteLine(exc.Message);
Console.ReadLine();
}
这是我的app.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyWebService1"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:7002/WSauth-WS_auth-context-root/MyWebService1Port"
binding="basicHttpBinding" bindingConfiguration="MyWebService1"
contract="TestWs.MyWebService1" name="MyWebService1Port" />
</client>
</system.serviceModel>
</configuration>
您能否注释掉a.Security.Mode=BasicHttpSecurityMode.TransportCredentialOnly;看看会发生什么?我得到了同样的解释。我已经用java为这个WS编写了客户端,一切都很好。WS部署在WebLogic 10.3.6上,并由它提供授权,也许这就是问题所在?