Using PHP SoapClient with Java JAX-WS RI (Webservi

2019-04-17 02:50发布

For a new project, we want to build a web service in Java using JAX-WS RI, and for the web service client, we want to use PHP.

In a small tutorial about JAX-WS RI I found this example web service:

package webservice;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public class Calculator {
    public long addValues(int val1, int val2) {
        return val1 + val2;
    }
}

and for the web server:

package webservice;

import javax.xml.ws.Endpoint;
import webservice.Calculator;

public class CalculatorServer {
    public static void main(String args[]) {
        Calculator server = new Calculator();
        Endpoint endpoint = Endpoint.publish("http://localhost:8080/calculator", server);
    }
}

Starting the Server and browsing the WDSL with the URL "http://localhost:8080/calculator?wsdl" works perfectly. But calling the web service from PHP fails.

My very simple PHP call looks like this:

$client = new SoapClient('http://localhost:8080/calculator?wsdl', array('trace' => 1));
echo 'Sum: '.$client->addValues(4, 5);

But then I either get a "Fatal error: Maximum execution time of 60 seconds exceeded..." or an "Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost:8080/calculator?wsdl' ..." exception.

I have tested the PHP SoapClient() with other web services and they work without any issues. Is there a known issue with JAX-WS RI in combination with PHP, or is there an error in my web service I didn't see?

I have found this bug report, but even updating to PHP 5.3.2 didn't solve the problem.

Can anyone tell me what to do? And by the way, my Java version running on Windows 7 x64 is the following:

java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

1条回答
在下西门庆
2楼-- · 2019-04-17 03:36

If it times out it looks like php isn't able to resolve the WSDL URL properly. Have you tried a file_get_contents()/curl on the WSDL Url? Maybe try calling the IP instead of localhost and see how that goes.

查看更多
登录 后发表回答