简体   繁体   中英

PHP SoapClient against Java Server

I am at the end of my ropes so its time to ask the community for help, i've been pillaging the web for any resource I can find on this issue but none helps me.

I am currently trying to communicated with a Java Webservice server through PHP. I can pull down a WSDL and list its functions and types through __getFunctions(); and __getTypes();

I am creating the client in this format

new SoapClient("https://username:password@ip:port/path/to/wsdl?wsdl");

Now initially this poses no problems, but when I try to make a function call on this service I get 1 of 2 responses.

I know one of them is a timeout error, the second one I do not understand as of yet.

Error : SoapFault exception: [SOAP-ENV:Client] [MT-IP] SOAP message is not well formed in...

Here is the code:

// All of this works

$options["login"]    = "login";
$options["password"] = "password";

$wsdl   = "https://" . $options["login"] . ":" . $options["password"] . "@ip:port/path/to/wsdl?wsdl";
$client = new SoapClient($wsdl, $options);

try {
    $functions = $client->__getFunctions();
    $types     = $client->__getTypes();

    $params = new stdClass();
    $params->pong = (string)"Hello World!";

    // This fails

    $result = $client->ping($params);
    var_dump($result);
} catch (SoapFault $exception) {
    echo $exception;
}

To add I have also attempted to call methods in all the ways available such as

$client->__soapCall("ping", array($params));
$client->__soapCall("ping", array(array("pong" => "Hello World!)));
$client->__soapCall("ping", array("pong" => "Hello World"));
$client->__soapCall("ping", array("parameters" => array("pong" => "Hello World"));

// and some more..

You can also see the WSDL I am testing against WSDL

You can also view the page where I try to call webservice SOAP TEST

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="com.computas.mt.extern.Ping">
    <SOAP-ENV:Body>
        <ns1:ping>
            <pong>Hello World!</pong>
        </ns1:ping>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

In my case the schematics the server wanted was different than that of the request PHP was sending out. The solution was to physically change the request XML before it was sent out by extending the SoapClient. We found the changes to the issue once we had the XML layout that the server usually gets provided with.

class MySoapClient extends SoapClient {
    function __doRequest( $request, $location, $action, $version, $one_way = NULL ) {
        $request = str_replace("SOAP-ENV", "soapenv", $request);
        $request = str_replace("xsi", "com", $request);
        $request = str_replace("ns1", "com", $request);
        var_dump($request);
        return parent::__doRequest( $request, $location, $action, $version, $one_way );
    }
}

Do not put username and password into the url. SoapClient accepts an option array that offers parameters for this purpose. http://de2.php.net/manual/en/soapclient.soapclient.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM