0

我的组件具有复杂的接口与接受非原始数据或简单 POJO 的操作。

将此组件接口转换为可供 java 和非 java 客户端使用的标准 Web 服务接口的最佳实践(方式/方法)是什么,以便服务使用者可以使用 WSDL 毫无问题地生成类。

可以按原样使用吗?如果没有,有没有办法在不影响操作行为的情况下最小化改变它?

组件接口有如下操作:

/** This is asynchronous method that needs to callback the ResultHandler
    interface which has to be implemented by the component user to handle
    operationOne result **/
public void operationOne(int id, ResultHandler handler);

/** I think there is no problem with the following operation for Web Services,
    when using data contracts. Correct me if I’m wrong! **/
public String operationTwo(int id, MyObject obj);

ResultHandler 接口:

/** Note that this handler interface contains InputStream
    and Exception as parameters for the handling methods **/ 
interface ResultHandler {
    void onComplete(InputStream is); 
    void onFailure(IOException ioEx); 
}
4

2 回答 2

0

您需要创建一个可以使用提供的参数调用组件并返回完整响应的方法。为了获得最佳结果,该方法不应有副作用。

然后向其中添加@WebService 和@WebMethod 注释,并使用 Endpoint.publish(...) 创建一个小的独立应用程序来发布该 Web 服务。Java 6 中的 JAX-WS 堆栈可以由此自动生成 WSDL。

有关执行此操作的完整教程,请参阅http://java.dzone.com/articles/jax-ws-hello-world

于 2013-04-02T07:50:24.040 回答
0

您可以在 webmethods 中使用您的对象,因为它们被转换为复杂的 WSDL 类型,但请记住,这只能在一定程度上完成。您应该使用简单的 POJO 来传输数据结构,以便您从 WSDL/代码生成中受益,而不是使用您将用于执行业务职责的复杂类型。还有一个建议,应该是 REST/JSON over SOAP Web 服务。

更新:

有效测试 Web 服务的唯一方法是为 Web 服务上的每个调用创建一个 moke。

Moq - 如何模拟 Web 服务调用?

于 2013-04-01T13:39:17.427 回答