doubutao6216 2013-03-02 01:05
浏览 40

如何在PHP中进行php WSSoapClient调用 - 示例

Can someone provide me a PHP example of how to make a WSSoapClient call to a wsdl webservice at https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl .

I have looked everywhere for code examples and could not find how to call this. i see that you can extend the SoapClient class but i am lost on how to structure the call itself. thank you so much.

Example"

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ser="http://server.webservices.web.v2.pagosonline.net"> 
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" 
 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-    secext1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>1</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-    token-profile-1.0#PasswordText">
123456</wsse:Password>
</wsse:UsernameToken>
</wsse:Security> 
</soapenv:Header>
<soapenv:Body>
<ser:getVersion soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body></soapenv:Envelope>
  • 写回答

1条回答 默认 最新

  • donglue1886 2013-03-02 02:12
    关注

    Firstly, you need to initialize a new SoapClient object, passing in the URL to your WSDL file like so:

    $client = new SoapClient("https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl");
    

    Then you can call service methods like any other object method like so:

    $verificaCuenta = true;
    $result = $client->setVerificaCuenta($verificaCuenta);
    

    To get a list of all available methods, once you have created your $client object, you can call __getFunctions() like this:

    $client = new SoapClient("https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl");
    $functions = $client->__getFunctions();
    var_dump($functions);
    

    Note: you must have php_soap and php_openssl enabled in your php.ini file for this to work.

    Edit: Seems like the service you are calling requires wsse headers. I'm no expert, but it looks like PHP does not have great support for that kind of thing.

    Found a project on Google Code that appears to make wsse easy with PHP. Link here: https://code.google.com/p/wse-php/source/browse/

    You can just grab the soap-wsse.php and the xmlseclibs.php files.

    Then include the soap-wsse.php file into your code and extend the soap client like this:

    require "soap-wsse.php";
    class mySoap extends SoapClient {
    
        function __doRequest($request, $location, $saction, $version) {
            $doc = new DOMDocument('1.0');
            $doc->loadXML($request);
    
            $objWSSE = new WSSESoap($doc);
    
            $objWSSE->addUserToken("YOUR_USERNAME_HERE", "YOUR_PASSWORD_HERE", TRUE);
    
            return parent::__doRequest($objWSSE->saveXML(), $location, $saction, $version);
        }
    }
    

    Then you should be able to talk to the webservice like this:

    $wsdl = 'https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl';    
    $sClient = new mySoap($wsdl, array('trace'=>1));
    
    try {
        $verificaCuenta = true;
        $result = $sClient->setVerificaCuenta($verificaCuenta);
        print_r($result->return);
    } catch (SoapFault $fault) {
        print("Fault string: " . $fault->faultstring . "
    ");
        print("Fault code: " . $fault->detail->WebServiceException->code . "
    ");
    }
    
    echo $sClient->__getLastRequest() . "
    " . $sClient->__getLastResponse();
    

    Disclaimer

    I have not tested any of the above code, hopefully it can put you on the right path.

    Good luck

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算