java调用WebServices时invoke方法迟迟不返回。
java项目中需要调用一个delphi平台用remobjects发布的接口,搞来了RemObjects for java的实例和服务端,服务端发布有两个模式:Synapse和Indy选择Indy启动后在http://localhost:8099/soap可以看到wsdl文件,以此在eclipse中用axis生成webservices客户端之后调用一切正常。
选择Synapse启动后,http://localhost:8099/soap下的wsdl文件和Indy的区别是地址变成了相对地址
<wsdl:service name="MegaDemoService"><xs:annotation><xs:documentation>
Service_NewService__This_service_has_been_automatically_generated_using_the_RODL_template_you_can_find_in_the_Templates_directory_
</xs:documentation></xs:annotation><wsdl:port name="MegaDemoServicePort" binding="tns:MegaDemoServiceBinding"><soap:address location="/soap?service=MegaDemoService"/></wsdl:port></wsdl:service>
而用Indy发布时的地址是<soap:address location="http://localhost:8099/soap?service=MegaDemoService"/>;
问题来了,此时用http://localhost:8099/soap去生成客户端文件时会报错:
IWAB0399E Error in generating Java from WSDL:
java.io.IOException: Emitter failure.
Invalid endpoint address in port MegaDemoServicePort in service MegaDemoService_ServiceLocator: /soap?service=MegaDemoService
java.io.IOException: Emitter failure.
Invalid endpoint address in port MegaDemoServicePort in service MegaDemoService_ServiceLocator: /soap?service=MegaDemoService
at org.apache.axis.wsdl.toJava.JavaServiceImplWriter.writeFileBody
而用第一次生成的代码去调用时可以返回结果,但是这个结果要等3~5分钟才会返回
调试发现程序到执行call.invoke()方法时就等在那了,而此时服务端是有接受到数据并返回了的,为什么invoke方法会一直卡3~5分钟才解析出返回结果呢?而在等待的时候将服务端关闭的话程序就立即往下执行并返回正确的结果了。。。。。。
有没有大神知道这个怎么解决啊?或者这种动态wsdl地址的接口应该怎么接?
附上客户端调用代码:
MegaDemoService_Service services=new MegaDemoService_ServiceLocator();
MegaDemoService_PortType port =services.getMegaDemoServicePort(new URL("http://localhost:8099/soap?service=MegaDemoService"));
System.out.println("start");
long start=System.currentTimeMillis();
int a= port.sum(4, 7);
System.out.println("use time:"+(System.currentTimeMillis()-start));
System.out.println(a);
MegaDemoServiceBindingStub中sum方法
public int sum(int a, int b) throws java.rmi.RemoteException {webservices RemObjects wsdl soap
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[0]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI("urn:MegaDemoLibrary-MegaDemoService#Sum");
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName("urn:MegaDemoLibrary-MegaDemoService", "Sum"));
setRequestHeaders(_call);
setAttachments(_call);
try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Integer(a), new java.lang.Integer(b)});
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
try {
return ((java.lang.Integer) _resp).intValue();
} catch (java.lang.Exception _exception) {
return ((java.lang.Integer) org.apache.axis.utils.JavaUtils.convert(_resp, int.class)).intValue();
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
throw axisFaultException;
}
}
补充:Java , Java EE