使用SoapClient over https在PHP中调用WCF时出现致命错误

时间:2013-03-19 10:20:44

标签: php wcf wsdl webservice-client soap-client

我是服务的新手,我目前使用SoapClient对象在PHP中调用.net WCF服务。代码如下:

    $arr2=array('paymentVendorCode'=>"test1",'transactionNumber'=>123456789,'dataSource'=>'Ghana_QA','customerNumber'=>45678912,'amount'=>10,'invoicePeriod'=>1,'currency'=>'GHC','paymentDescription'=>'CashPayment','methodofPayment'=>'CASH','productCollection'=>'PRCC4');

    $certFile = "certs/Entrust.pem";
    $options = array('soap_version' => SOAP_1_1 , 'local_cert' => $certFile , 'exceptions' => true ,'trace' => true ,'wdsl_local_copy' => true ,'ssl' => array('verify_peer' => false) ,'https' => array('curl_verify_ssl_peer'  => false, 'curl_verify_ssl_host' => false)
           );

try
{
echo "SOAP Client Object Made <br />";
//To Make soap client using WSDL files offline
$client = new SoapClient("RTPP_Web_Service_WSDL_20130306/multichoice.paymentservice.wsdl",$options);    
}
catch(SoapFault $E)
{
    echo "Error:--> ".$E->faultstring;
}

print_r($client->__getFunctions());

try
{
echo $pmt_customer=$client->__call("SubmitPayment", $arr2)."<br /><br />";
}
catch(SoapFault $fault)
{
echo "came here in catch";
trigger_error("SOAP Fault:(faultcode: {$fault->faultcode}\n"."faultstring: {$fault->faultstring})", E_USER_ERROR);  
 }

我已经浏览了我正在使用的所有WSDL文件,并获得了所有元素,消息,操作,参数等。其中一个WSDL文件的soap地址如下:

<soap:address location="https://wispqa.multichoice.co.za/PaymentServicePerimeter/Intermediate.svc" />

这是被调用服务的实际地址,通常在url末尾使用?WSDL调用服务,但即使在上面的url末尾添加它之后,服务页面外观也保持不变。

服务文档中的一件事写成“服务当前不使用消息合同”。

我发送请求服务,通过调用“$ client-&gt; __ getFunction()”从我获得的列表中调用其中一个方法。但是,不是回应,而是从http://i.stack.imgur.com/GvS3d.png的屏幕截图中看到致命的错误。

我已经工作了将近一个星期,但却陷入了困境。如果有人可以让我离开这里。提前谢谢。

1 个答案:

答案 0 :(得分:0)

我得到了答案,我缺少的是要调用方法的soap动作。我通过彻底访问WSDL文件给出了肥皂操作,并发现方法i的肥皂操作称为:

  $submitpayment_action   = "http://MultiChoice.PaymentService/ServiceContracts/PaymentServiceContract/SubmitPayment";

此外,我已使用xml格式更改了我的请求格式,其摘录如下(我使用SOAPUI工具获得此xml格式):

 $submitpay = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:mes=\"http://MultiChoice.PaymentService/MessageContracts\" 
                                        xmlns:ser=\"http://MultiChoice.PaymentService/ServiceContracts\" 
                                        xmlns:dat=\"http://MultiChoice.PaymentService/DataContracts\" 
                                        xmlns:mcom=\"http://mcomp.scontracts\" xmlns:mcom1=\"http://mcomp.dcontracts\">
                      <soapenv:Header/>
<soapenv:Body>
                        <mes:SubmitPaymentRequest>
                          <ser:PaymentRequest>
<dat:paymentVendorCode>".$vendorcode."</dat:paymentVendorCode> .......

最后使用这个“__doRequest”SOAP方法将服务方法调用为:

 $response = $client->__doRequest($submitpay,$location,$submitpayment_action,SOAP_1_1,$one_way = 0);

print_r($response);

这向我展示了理想的回应。现在可以使用“simplexml_load_string($ response);”从响应中提取所需的信息。 ,“registerXPathNamespace()”和“xpath('// string');”方法