0

我通过此 url 获得了 MyService(AXIS 1.4 服务):

curl http://localhost:9999/prefix/services/MyService?wsdl

将它放到浏览器查询行中,我返回了 XML WSDL。

问题是:我应该在代码中使用哪个 URL 来连接到 MyService 以在那里调用特定的方法?

这是我现在的连接代码:

InterfacePortType_Stub stub 
                              = (InterfacePortType_Stub) myService.getPort();

stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, 
    "http://localhost:9999/prefix/services/MyService");

this.port = stub;

final MyResponse myResponse = port.myMethod(myRequest);

所以,我用**http://localhost:9999/prefix/services/MyService**字符串来连接。但它不起作用 - myResponse.status = 失败。

在我生成的文件的顶部,我有一个像这样的标题:

// This class was generated by the JAXRPC SI, do not edit.
// Contents subject to change without notice.
// JAX-RPC Standard Implementation (1.1.2_01, build R40)
// Generated source version: 1.1.2
4

1 回答 1

1

要调用 Axis 服务,首先需要对其进行正确初始化。您的代码应如下所示:

//Your service interface.
InterfacePortTypeService proxy = null;

//Create a locator instance from Axis generated class.
InterfacePortTypeLocator locator = new InterfacePortTypeLocator();

//Get your service from locator.
proxy = locator.getInterfacePortType(new URL("http://localhost:9999/prefix/services/MyService"));

//Call your methods;
proxy.someMethod();

我不知道您生成的所有类的名称,所以这只是一个如何初始化Axis服务的示例。

于 2012-09-27T17:48:11.457 回答