3

我在使用 PHP 的 wsHttpBinding WCF 时遇到了一些问题。我最初尝试使用 SOAP1.2,但无法指定 WS Action。

我下载了 nusoap 库。我最初收到一条错误消息,指出由于类型不匹配(文本/xml 而不是预期的应用程序/soap+xml),webservice 不会接受数据。我设法对 nusoap.php 进行了更改,以将数据作为 application/soap+xml) 发送。现在这不会引发错误,我从服务器收到 400 bad request 错误。

我可以使用 WCFTestClient 和 SOAPUI 提供的服务,而不会造成任何混乱,但不能让它从 PHP 中运行。我什至从 SOAPUI 复制了整个肥皂信封,并将 nusoap.php 中的 $soapmsg 设置为完全一样,但它仍然失败。

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

编辑 这是我在 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);
}

编辑#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>

按照下面的 Gords 链接手动添加 SoapHeaders 后,我在使用 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>

有什么建议吗??

谢谢!安迪

4

1 回答 1

6

好的,所以我得到了这个工作。感谢 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 服务的 web.config 文件

<?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>
于 2013-04-05T22:24:41.643 回答