0

我是服务新手,我目前正在使用 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->__getFunction()”获得的列表中调用其方法之一的服务发送请求。但它不是响应而是给出致命错误,可以从http://i.stack.imgur.com/GvS3d.png的屏幕截图中看到。

我已经为此工作了将近一个星期,但被困在这里。请如果有人可以让我离开这里。提前致谢。

4

1 回答 1

0

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

  $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');" 方法。

于 2013-05-07T10:11:35.480 回答