0
我正在編寫一個客戶端應用程序,它將使用Web服務並應能夠獲取數據。使用web服務的wsdl,我在客戶端應用程序中生成了代理類。我遵循「添加服務引用」方法來生成代理。現在,當我嘗試訪問web服務上的方法時,出現此錯誤:「既未提供UsernameToken也未提供Signature」。我的第一個嫌疑人是它需要憑據,我試圖在我的代碼中提供它們。但我仍然看到這個問題。我在代碼中提供證書的原因是因爲我們有2個Web服務,一個是質量保證,另一個是生產。他們的wsdl是相同的,但憑證是不同的,所以我將使憑證可配置,以便最終用戶可以根據他們想要訪問的Web服務輸入它。訪問Web服務上的方法時出現異常
請讓我知道,如果有什麼我失蹤。由於
這裏是我的代碼(這是一個小的測試片段來測試Web服務調用):
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>
我試了你的代碼中的邏輯,但它沒有奏效。 – marak