2014-03-31 163 views
3

我有工作的PHP代碼調用SOAP服務,它的工作原理。它如下:從C調用肥皂服務#

<?php 
try 
{ 
    $client = new SoapClient(null, array(
     'location' => "http://108-168-196-91.mycitrixdemo.net/zdm/services/EveryWanDevice?wsdl", 
     'uri' => "http://zdemo2.zenprise.com", 
     'login' => "Admin", 
     'password'=> "XXXXX")); 

    $properties=$client->getDeviceProperties("XXXXXXXX",null); 

    for($i=0;$i<count($properties);$i++) { 
     printf ("name: %s, value: %s\n" , $properties[$i]->name, $properties[$i]->value); 
    } 
} 
catch (Exception $e) 
{ 
    print_r($e); exit; 
} 
?> 

我需要從C#訪問相同的服務。我曾嘗試將Service Reference添加到http://108-168-196-91.mycitrixdemo.net/zdm/services/EveryWanDevice?wsdl,並在我的app.config中添加了以下部分。

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="EveryWanDeviceSoapBinding" /> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://108-168-196-91.mycitrixdemo.net/zdm/services/EveryWanDevice" 
      binding="basicHttpBinding" bindingConfiguration="EveryWanDeviceSoapBinding" 
      contract="ServiceReference1.DeviceService" name="EveryWanDevice" /> 
    </client> 
</system.serviceModel> 

我現在提供了代理類,但我不知道如何設置它們以便我可以調用此服務。

我這樣做如下的C#:

DeviceService srv = new DeviceServiceClient();// 
srv.authenticateUser(new authenticateUserRequest("Admin", "XXXXXX")); 

var devices = srv.getDeviceProperties(new getDevicePropertiesRequest("99000067296308", null)); 

srv.authenticateUser行拋出以下異常:

RPC Message getDeploymentHistoRequest1 in operation getDeploymentHisto1 has an invalid body name getDeploymentHisto. It must be getDeploymentHisto1 

我不知道這是什麼意思的錯誤。任何人都可以幫忙嗎?

回答

1

要我這個錯誤看起來像你生成代理文件的問題。您可能想要使用svcutil重新進行代理以確保正確生成代理文件。在你的情況,你的Visual Studio開發工具的命令在命令看起來是這樣的...

svcutil.exe /language:cs /out:Proxies.cs /config:output.config [service url] 

它也不像你在第一時間建立安全會話。將您的綁定更改爲以下內容...

<binding name="EveryWanDeviceSoapBinding" 
     closeTimeout="00:01:00" 
     openTimeout="00:01:00" 
     receiveTimeout="00:10:00" 
     sendTimeout="00:01:00" 
     allowCookies="false" 
     bypassProxyOnLocal="false" 
     hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="6553666" 
     maxBufferPoolSize="524288" 
     maxReceivedMessageSize="6553666" 
     messageEncoding="Text" 
     textEncoding="utf-8" 
     transferMode="Buffered" 
     useDefaultWebProxy="true"> 
    <security mode="Transport"> 
     <transport clientCredentialType="Basic" 
        proxyCredentialType="Basic" 
        realm="" /> 
     <message clientCredentialType="UserName" 
       algorithmSuite="Default" /> 
    </security> 
</binding> 

絕大多數這些只是服務綁定的基本默認值。該security部分就是應該讓你建立像這樣的服務的安全連接...

var srv = new DeviceServiceClient(); 

srv.ClientCreditials.UserName.UserName = "Admin"; 
srv.ClientCreditials.UserName.Password = "XXXXX"; 

最後,你可以調用getDeviceProperties方法與你的論點,並得到某種迴應的背部。