Java Webservice 客户端(最佳方式)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3588616/
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-08-14 02:14:04  来源:igfitidea点击:

Java Webservice Client (Best way)

javajax-wsaxis2wsdl2javawebservice-client

提问by Java Guy

I have a third party WSDL, I need to write code in Java for a web service client to invoke the operations in the third party WSDL. Right now, I have generated the client stub using the WSDL2JAVA tool from Axis and used the XMLbeans for data binding.

我有一个第三方 WSDL,我需要用 Java 编写代码供 Web 服务客户端调用第三方 WSDL 中的操作。现在,我已经使用 Axis 的 WSDL2JAVA 工具生成了客户端存根,并使用 XMLbeans 进行数据绑定。

  1. What is the best approach to do this JAVA?
  2. I read about SAAJ, looks like that will be more granular level of approach?
  3. Is there any other way than using the WSDL2Java tool, to generate the code. Maybe wsimportin another option. What are the pros and cons?
  4. Can someone send the links for some good tutorials on these topics?
  5. What are the options we need to use while generating the code using the WSDL2Java?
  1. 执行此 JAVA 的最佳方法是什么?
  2. 我读过关于 SAAJ 的文章,看起来这将是更细粒度的方法?
  3. 除了使用 WSDL2Java 工具之外,还有其他方法可以生成代码吗?也许wsimport在另一种选择。优缺点都有什么?
  4. 有人可以发送有关这些主题的一些好的教程的链接吗?
  5. 在使用 WSDL2Java 生成代码时,我们需要使用哪些选项?

I used some of the basic things initially. Now I have these options

我最初使用了一些基本的东西。现在我有这些选择

C:\axis2-1.5.1\bin>wsdl2java -uri  mywsdlurl  -o client -p somepackage -d xmlbeans -s -t -ssi

回答by Steve

I have had good success using Spring WS for the client end of a web service app - see http://static.springsource.org/spring-ws/sites/1.5/reference/html/client.html

我在 Web 服务应用程序的客户端使用 Spring WS 取得了很好的成功 - 请参阅http://static.springsource.org/spring-ws/sites/1.5/reference/html/client.html

My project uses a combination of:

我的项目使用以下组合:

  • XMLBeans (generated from a simple Maven job using the xmlbeans-maven-plugin)

  • Spring WS - using marshalSendAndReceive() reduces the code down to one line for sending and receiving

  • some Dozer - mapping the complex XMLBeans to simple beans for the client GUI

  • XMLBeans(使用 xmlbeans-maven-plugin 从一个简单的 Maven 作业生成)

  • Spring WS - 使用 marshalSendAndReceive() 将用于发送和接收的代码减少到一行

  • some Dozer - 将复杂的 XMLBeans 映射到客户端 GUI 的简单 bean

回答by Mark O'Connor

Some ideas in the following answer:

以下答案中的一些想法:

Steps in creating a web service using Axis2 - The client code

使用 Axis2 创建 Web 服务的步骤 - 客户端代码

Gives an example of a Groovy client invoking the ADB classes generated from the WSDL.

给出一个 Groovy 客户端调用从 WSDL 生成的 ADB 类的示例。

There are lots of web service frameworks out there...

那里有很多 Web 服务框架...

回答by Pascal Thivent

What is the best approach to do this JAVA?

执行此 JAVA 的最佳方法是什么?

I would personally NOTuse Axis 2, even for client side development only. Here is why I stay away from it:

我个人不会使用 Axis 2,即使仅用于客户端开发。这就是我远离它的原因:

  1. I don't like its architecture and hate its counter productive deployment model.
  2. I find it to be low quality project.
  3. I don't like its performances (see this benchmark against JAX-WS RI).
  4. It's always a nightmare to setup dependencies (I use Maven and I alwayshave to fight with the gazillion of dependencies) (see #2)
  5. Axis sucked big time and Axis2 isn't better. No, this is not a personal opinion, there is a consensus.
  6. I suffered once, never again.
  1. 我不喜欢它的架构,讨厌它的适得其反的部署模型。
  2. 我发现它是低质量的项目。
  3. 我不喜欢它的性能(请参阅针对 JAX-WS RI 的基准测试)。
  4. 设置依赖项总是一场噩梦(我使用 Maven,我总是不得不与无数的依赖项作斗争)(见 #2)
  5. Axis 花了很多时间,Axis2 也好不到哪里去。不,这不是个人意见,有共识。
  6. 我受过一次,再也没有受过。

The only reason Axis is still around is IMO because it's used in Eclipse since ages. Thanks god, this has been fixed in Eclipse Helios and I hope Axis2 will finally die. There are just much better stacks.

Axis 仍然存在的唯一原因是 IMO,因为它已经在 Eclipse 中使用了很长时间。感谢上帝,这已在 Eclipse Helios 中修复,我希望 Axis2 最终会消亡。只有更好的堆栈。

I read about SAAJ, looks like that will be more granular level of approach?

我读过关于 SAAJ 的文章,看起来这将是更细粒度的方法?

To do what?

做什么?

Is there any other way than using the WSDL2Java tool, to generate the code. Maybe wsimport in another option. What are the pros and cons?

除了使用 WSDL2Java 工具之外,还有其他方法可以生成代码吗?也许 wsimport 是另一种选择。优缺点都有什么?

Yes! Prefer a JAX-WS stack like CXFor JAX-WS RI(you might also read about Metro, Metro= JAX-WS RI + WSIT), they are just more elegant, simpler, easier to use. In your case, I would just use JAX-WS RI which is included in Java 6 and thus wsimport.

是的!更喜欢像CXFJAX-WS RI这样的 JAX-WS 堆栈(您可能还阅读了 Metro,Metro= JAX-WS RI + WSIT),它们只是更优雅、更简单、更易于使用。在您的情况下,我将只使用 Java 6 中包含的 JAX-WS RI,因此wsimport.

Can someone send the links for some good tutorials on these topics?

有人可以发送有关这些主题的一些好的教程的链接吗?

That's another pro, there are plenty of (good quality) tutorials for JAX-WS, see for example:

这是另一个专业人士,JAX-WS 有很多(高质量)教程,例如:

What are the options we need to use while generating the code using the WSDL2Java?

在使用 WSDL2Java 生成代码时,我们需要使用哪些选项?

No options, use wsimport:)

没有选择,使用wsimport:)

See also

也可以看看

Related questions

相关问题

回答by aravindaM

You can find some resources related to developing web services client using Apache axis2 here.

您可以在此处找到与使用 Apache axis2 开发 Web 服务客户端相关的一些资源。

http://today.java.net/pub/a/today/2006/12/13/invoking-web-services-using-apache-axis2.html

http://today.java.net/pub/a/today/2006/12/13/invoking-web-services-using-apache-axis2.html

Below posts gives good explanations about developing web services using Apache axis2.

下面的帖子很好地解释了使用 Apache axis2 开发 Web 服务。

http://www.ibm.com/developerworks/opensource/library/ws-webaxis1/

http://www.ibm.com/developerworks/opensource/library/ws-webaxis1/

http://wso2.org/library/136

http://wso2.org/library/136