【发布时间】:2015-10-14 00:20:56
【问题描述】:
我正在编写一个客户端应用程序,它会使用 Web 服务并且应该能够获取数据。使用 web 服务的 wsdl,我在客户端应用程序中生成了代理类。我遵循“添加服务参考”的方法来生成代理。现在,当我尝试访问 web 服务上的方法时,我收到此错误:“既未提供 UsernameToken 也未提供签名”。我的第一个怀疑是它需要凭据,我试图在我的代码中提供它们。但我仍然看到这个问题。我在代码中提供凭据的原因是因为我们有 2 个 Web 服务,一个是 QA,另一个是生产。他们的 wsdl 相同,但凭据不同,因此我将配置凭据,以便最终用户可以根据他们想要访问的任何 Web 服务输入它。
如果我遗漏了什么,请告诉我。谢谢
这是我的代码(这是一个用于测试 web 服务调用的小测试 sn-p):
GetApplicationServiceClient client= new GetApplicationServiceClient();
client.ClientCredentials.UserName.UserName = "userId";
client.ClientCredentials.UserName.Password = "password";
int[] input= new int[3]{1,2,3};
GetAppResponse response= new GetAppResponse();
foreach (var item in input)
{
response = client.getAppById(item);
}
这是我的配置文件:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GetApplicationServiceSoapBinding">
<security mode="Transport" />
</binding>
<binding name="GetApplicationServiceSoapBinding1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://TestService.com/bo-service/v2/ws/get-application"
binding="basicHttpBinding" bindingConfiguration="GetApplicationServiceSoapBinding"
contract="TestService.GetApplicationService" name="GetApplicationServicePort" />
</client>
</system.serviceModel>
【问题讨论】:
标签: c# xml web-services