php使用WCF SSL SOAP客户端1.2
我在使用来自PHP的wsHttpBinding WCF时遇到一些问题。我最初尝试使用SOAP1.2,但无法让它指定WS操作 我下载了nusoap图书馆。我最初收到一个错误,说由于类型不匹配(text/xml而不是预期的应用程序/soap+xml),webservice不会接受数据。我设法对nusoap.php进行了更改,将数据作为application/soap+xml)发送。现在没有抛出错误,我从服务器上得到了400个错误的请求错误 我可以使用WCFTestClient和SOAPUI提供的服务,而不需要任何混乱,但我无法让它从PHP运行。我甚至从SOAPUI复制了整个soap信封,并将nusoap.php中的$soapmsg设置为完全相同的值,但仍然失败 所以任何人都想提供一些指导 编辑 这是我在SOAP1.2中尝试的代码php使用WCF SSL SOAP客户端1.2,php,wcf,ssl,nusoap,Php,Wcf,Ssl,Nusoap,我在使用来自PHP的wsHttpBinding WCF时遇到一些问题。我最初尝试使用SOAP1.2,但无法让它指定WS操作 我下载了nusoap图书馆。我最初收到一个错误,说由于类型不匹配(text/xml而不是预期的应用程序/soap+xml),webservice不会接受数据。我设法对nusoap.php进行了更改,将数据作为application/soap+xml)发送。现在没有抛出错误,我从服务器上得到了400个错误的请求错误 我可以使用WCFTestClient和SOAPUI提供的服务
$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>
http://tempuri.org/IService/GetData
东西
正如下面的Gords链接所提到的,在手动添加SoapHeaders之后,我在使用netbeans进行调试时得到了这个作为u last_请求的请求,仍然是相同的错误
"<?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>
”
http://tempuri.org/IService/GetData
东西
有什么建议吗
谢谢!
安迪好的,我把这个工作做好了。多亏戈尔让我仔细检查我之前忽略的东西 我放弃了nusoap,坚持使用SOAP 1.2
//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>
http://tempuri.org/IService/GetData
以及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>
如果您在PHP5上运行,您是否尝试过PHP内置的SOAP支持?我曾经维护过一个基于ASP.NET的web服务,该服务可以使用PHP5的SOAP实现调用,但无法从NuSOAP调用。(IIRC它与将参数作为对象传递给web服务有关,这是NuSOAP显然无法做到的。)Hi Gord。感谢您的回复。当我使用SOAP_客户端(与NuSOAP_客户端相反)时我会不断收到错误“消息上指定的SOAP操作”与HTTP SOAP操作不匹配”。这是我切换到nusoap的原因之一。您提到了SOAP_1.2,但您是否尝试使用WSDL?我记得(几年前)也是这样这是我发现的唯一可以让PHP与该web服务交互的方法。我尝试进一步深入研究它的几次,我都陷入了困境,因为MS文档都是关于从.NET应用程序中使用ASP.NET web服务,以及我能找到的大多数PHP引用(博客等)似乎对支持和MS相关的任何东西都不太感兴趣:(嗨,Gord。我用我在1.2中使用的代码更新了OP,我完全同意试图在php和MS之间实现互操作性只是一场噩梦!我找到了我的旧示例代码,它看起来和你们的非常相似,所以我可能无法提供“银弹”“对于此::(您是否碰巧遇到了堆栈溢出文章?我收到了以下错误:SOAP错误:(错误代码:s:Sender,错误字符串:验证消息安全性时出错。)