gpt4 book ai didi

php 使用 WCF SSL SOAP 客户端 1.2

转载 作者:可可西里 更新时间:2023-11-01 00:33:44 25 4
gpt4 key购买 nike

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

我下载了 nusoap 库。我最初收到一条错误消息,指出由于类型不匹配(text/xml 而不是预期的 application/soap+xml),web 服务不会接受数据。我设法对 nusoap.php 进行了更改,以将数据作为 application/soap+xml 发送)。现在没有抛出错误,我从服务器收到 400 错误请求错误。

我可以使用来自 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>

有什么建议吗??

谢谢!安迪

最佳答案

好的,所以我让它工作了。感谢 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>

关于php 使用 WCF SSL SOAP 客户端 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15841875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com