2013-04-05 108 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