java java中的动态代理soap web服务客户端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6447974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:55:08  来源:igfitidea点击:

dynamic proxy soap web service client in java?

javaweb-servicessoap

提问by javamonkey79

Is there any way to use soap-rpc web services such that the client is generated via a shared interface? Restful web services do it this way, but what about soap based? Do you always have to use a tool like Axis or CXF to generate your stubs and proxies, or is there something out there that will set it up dynamically?

有没有办法使用soap-rpc Web服务,以便通过共享接口生成客户端?Restful Web 服务就是这样做的,但是基于soap 的服务呢?您是否总是需要使用 Axis 或 CXF 之类的工具来生成存根和代理,或者是否有可以动态设置的工具?

Thanks.

谢谢。

EDIT #1:

编辑#1:

To clarify, I'm looking to do something like this:

澄清一下,我正在做这样的事情:

Common interface:

通用接口:

@WebService
public interface MyWebService {

   @WebMethod
   String helloWorld();
}

This common interface can already be used to create the server side component. My question is: can this type of common interface be used on the client side to generate dynamic proxies?Restful web services do it this way (Restlets & CXF) and it seems the .Net world has this type of functionality too.

此通用接口已可用于创建服务器端组件。我的问题是:这种类型的通用接口可以在客户端使用来生成动态代理吗?Restful Web 服务就是这样做的(Restlets 和 CXF),看起来 .Net 世界也有这种类型的功能。

采纳答案by mico

I would see this tutorial of JAX-WSuseful for your purposes:

我会看到这个 JAX-WS 教程对您有用:

In the example code the Web Services Client is configured by adding an annotation @WebServiceRefwith a property pointing to the WSDL location to the client implementation class and no tools are needed to access the stuff from the Web Service that is referenced.

在示例代码中,通过向@WebServiceRef客户端实现类添加一个带有指向 WSDL 位置的属性的注释来配置 Web 服务客户端,并且不需要任何工具来访问来自所引用的 Web 服务的内容。

Was this the way you would like to have it, or did this even answer to right question?

这是您想要的方式,还是这甚至回答了正确的问题?

回答by kschneid

Not exactly sure what you're looking for, but if you don't want to rely on JAX-WS/JAXB-generated artifacts (service interfaces and binding objects), you can make use of the Serviceand DispatchAPIs. For example:

不完全确定您在寻找什么,但如果您不想依赖 JAX-WS/JAXB 生成的工件(服务接口和绑定对象),您可以使用ServiceDispatchAPI。例如:

QName serviceName = new QName(...);
Service service = Service.create(serviceName);
QName portName = new QName(...);
String endpointAddress = "...";
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
SOAPMessage request = ...;
SOAPMessage response = dispatch.invoke(request);

回答by Grigoris Grigoriadis

回答by Parth

When you want to call a webservice, you must have knowledge of methods implemented on it. For that, We need to make stubs OR we can read it from WSDL.

当您要调用 Web 服务时,您必须了解在其上实现的方法。为此,我们需要制作存根,或者我们可以从 WSDL 中读取它。

I have created a WS client, using AXIS2 libraries, which is without stubs. The thing is, for each diff. WS we need to create response handles.

我使用 AXIS2 库创建了一个 WS 客户端,它没有存根。问题是,对于每个差异。WS 我们需要创建响应句柄。

You can call any WS method using SOAP envelops and handle the response.

您可以使用 SOAP 信封调用任何 WS 方法并处理响应。

//common interface for response handlers...
//implement this for diff. web service/methods

public interface WSRespHandler{
    public Object getMeResp(Object respData);
}

//pass particular handler to client when you call some WS
public class WebServiceClient {
    public Object getResp(WSRespHandler respHandler) {
        ...
        return repHandler.getMeResp(xmlData);
    }
}

Please check the link below, which shows the example interface for WS client.

请查看下面的链接,其中显示了 WS 客户端的示例界面。

http://javalibs.blogspot.com/2010/05/axis2-web-service-client-without.html

http://javalibs.blogspot.com/2010/05/axis2-web-service-client-without.html

For every diff. WS method we can have diff. implementation for WSRespHandlerinterface, which will help parsing the response.

对于每个差异。WS 方法我们可以有差异。WSRespHandler接口的实现,这将有助于解析响应。

回答by FlexibleCoder

Not knowing java so well, but being forced to learn some to accomplish a task that I was given, I needed to consume a .Net service that I have already written, I had to do a little research.

对java不太了解,但被迫学习一些来完成给我的任务,我需要使用我已经编写的.Net服务,我不得不做一些研究。

I found that 99% of the examples/samples/problems with invoking a method call against a .Net service, or any service for that matter involved using J2EE (ServiceManager) or build classes and a proxy that reflect the service being invoked. Unfortunately for me, none of this would work. I was working "in a box". I could not add new classes, could not WSDL references, did not have J2EE, but DID have access to the standard java libs. I am used to doing this sort of thing in pretty much every other language but java, but now there was no choice, and java it was.

我发现 99% 的示例/示例/问题都涉及对 .Net 服务调用方法调用,或者涉及使用 J2EE (ServiceManager) 或构建类以及反映被调用服务的代理的任何服务。不幸的是,对我来说,这些都行不通。我在“盒子里”工作。我不能添加新类,不能 WSDL 引用,没有 J2EE,但 DID 可以访问标准的 java 库。我习惯于用除 Java 之外的几乎所有其他语言来做这种事情,但现在别无选择,而 Java 就是这样。

A lot of digging and figuring out all new terminology, methods, classes, etc, I knew I was getting close, but was having issues with some small items to complete the task. Then I came across this post: http://www.ibm.com/developerworks/xml/library/x-jaxmsoap/

大量挖掘和找出所有新术语、方法、类等,我知道我已经接近了,但是在完成任务的一些小项目上遇到了问题。然后我看到了这篇文章:http: //www.ibm.com/developerworks/xml/library/x-jaxmsoap/

As long as you have some sort of idea of what you need to send the soap service in term of the soap envelope, the above link will give you the information you need to be able to invoke a service without the classes, wsdl class generators and J2EE, apache or other dependencies.

只要您对在soap信封方面发送soap服务需要什么有某种想法,上面的链接就会为您提供无需类、wsdl类生成器和J2EE、apache 或其他依赖项。

In an hour from the time I read the mentioned article, I had a class working and about 10 minutes later, converted the code to the "in the box" solution.

在我阅读上述文章后的一个小时内,我有一堂课在工作,大约 10 分钟后,将代码转换为“in the box”解决方案。

Hope this helps

希望这可以帮助

回答by MarianP

Apache Tuscany might help you, although it may be heavier than you want http://tuscany.apache.org/

Apache Tuscany 可能会帮助你,虽然它可能比你想要的要重 http://tuscany.apache.org/