2013-04-05 106 views
3

我有一些問題,從PHP消耗wsHttpBinding WCF。我最初嘗試使用SOAP1.2,但無法讓它指定WS Action。php消費WCF SSL SOAP客戶端1.2

我下載了nusoap庫。我最初得到一個錯誤,說Web服務不會接受由於類型不匹配而導致的數據(text/xml,而不是預期的應用程序/ soap + xml)。我設法修改nusoap.php來發送數據作爲application/soap + xml)。現在,這不會引發錯誤,我從服務器得到400錯誤的請求錯誤。

我可以從WCFTestClient和SOAPUI中使用服務,而不需要任何弄亂,但是無法從PHP中獲取它。我甚至從SOAPUI複製了整個SOAP信封,並將nusoap.php中的$ soapmsg設置爲完全一樣,但仍然失敗。

所以任何人都想提供一些指導。

EDIT 這是我試圖在SOAP代碼1.2

$params = array("soap_version"=> SOAP_1_2, 
       "trace"=>1, 
       "exceptions"=>0, 
       ); 

$client = @new SoapClient('https://localhost/wcftest/Service.svc?wsdl',$params); 

$retval = $client->GetData(array('value'=>'stuff')); 
if (is_soap_fault($retval)) { 
    trigger_error("SOAP Fault: (faultcode: {$retval->faultcode}, faultstring: {$retval->faultstring})", E_USER_ERROR); 
} 

EDIT#2 這是可以算出SOAPUI

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"> 
    <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://tempuri.org/IService/GetData</wsa:Action></soap:Header> 
    <soap:Body> 
     <tem:GetData> 
     <!--Optional:--> 
     <tem:value>stuff</tem:value> 
     </tem:GetData> 
    </soap:Body> 
</soap:Envelope> 

的手動添加的SOAPHeaders之後的代碼正如Gords鏈接下面提到的那樣,我在使用netbeans進行調試時將此作爲__last_request,並且仍然是相同的錯誤

"<?xml version="1.0" encoding="UTF-8"?> 
    <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/"> 
<env:Header> 
<ns1:Action>http://tempuri.org/IService/GetData</ns1:Action> 
</env:Header> 
<env:Body><ns1:GetData><ns1:value>stuff</ns1:value></ns1:GetData></env:Body></env:Envelope> 

有什麼建議?

謝謝! Andy

+2

web.config文件如果你在PHP5運行你嘗試PHP的內置的SOAP支持?我曾經維護一個基於ASP.NET的Web服務,可以使用PHP5的SOAP實現來調用,但不能從NuSOAP調用。 (IIRC它與將對象作爲對象傳遞給Web服務的參數有關,這是NuSOAP顯然無法做到的。) – 2013-04-05 19:31:33

+0

嗨,Gord。謝謝回覆。當我使用SOAP_CLIENT(而不是Nusoap_client)時,我將不斷得到錯誤 '消息中指定的SOAP操作''與HTTP SOAP操作'http://tempuri.org/IService/'不匹配的GetData。這是我轉換到nusoap的原因之一。 – 2013-04-05 19:32:45

+1

您提到了SOAP_1.2,但您是否嘗試過使用WSDL?同樣,我還記得(這是幾年前),這是我發現可以讓PHP與該Web服務交互的唯一方式。我試圖進一步挖掘它的幾次我陷入困境,因爲MS文檔都是關於從.NET應用程序中使用ASP.NET Web服務的,並且大部分我可以找到的PHP引用(博客等)似乎都沒有非常有興趣支持與MS有關的任何事情。:( – 2013-04-05 19:49:58

回答

5

好的,所以我得到了這個工作。感謝Gord讓我對之前忽略的東西進行了雙重檢查。

我結束了對nusoap的拋棄,只是堅持使用SOAP 1.2。這是我的PHP代碼

//Declare some paramaters for our soapclient. Need to make sure its set to soap 1.2 
$params = array("soap_version"=> SOAP_1_2, 
       "trace"=>1, 
       "exceptions"=>0, 
       ); 

//Create the soap client 
$client = new SoapClient('https://localhost/wcftest/Service.svc?wsdl',$params); 
//add some WSAddressing Headers in. Ensure that you have the Namespace as the address if you are using wsHttpBinding on the endpoint 
//This was the step that took me the longest to figure out! 
$actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing','Action','http://tempuri.org/IService/GetData',true); 
//Add the headers into the client 
$client->__setSoapHeaders($actionHeader); 
//Make the call and pass in the variables that we require to go to the server 
$retval = $client->__soapCall('GetData',array('value'=>'stuff')); 
//Some Error Catching 
if (is_soap_fault($retval)) { 
    trigger_error("SOAP Fault: (faultcode: {$retval->faultcode}, faultstring: {$retval->faultstring})", E_USER_ERROR); 
} 

和工作方框

<?xml version="1.0" encoding="UTF-8"?> 
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://www.w3.org/2005/08/addressing"> 
    <env:Header> 
     <ns2:Action env:mustUnderstand="true">http://tempuri.org/IService/GetData</ns2:Action> 
    </env:Header> 
    <env:Body> 
     <ns1:GetData/> 
    </env:Body> 
</env:Envelope> 

,並從WCF服務

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    </system.web> 
    <connectionStrings> 
    <add name="Timeforce" connectionString="Data Source=apps.ziptrek.com;Initial Catalog=qqest;User ID=qqest; Password=qqest;" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="TransportSecurity"> 
      <security mode="Transport"> 
      <transport clientCredentialType="None"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service name="Service" behaviorConfiguration="Service1"> 
     <endpoint address="https://localhost/wcftest/Service.svc" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="IService"></endpoint> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Service1"> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpsGetEnabled="true"/> 

      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="httpsService1"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false"/> 


    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 
+2

+ 1很高興聽到你的工作! – 2013-04-05 22:38:49

+0

我得到這個錯誤:SOAP錯誤:(錯誤代碼:s:發件人,faultstring:驗證郵件的安全性時發生錯誤。) – 2015-06-26 08:33:24