Java Web 服务客户端(最佳方式)

Java Web 服务客户端(最佳方式)

问题描述:

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

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.

  1. 执行此 JAVA 的最佳方法是什么?
  2. 我读过关于 SAAJ 的文章,看起来这会是更细粒度的方法吗?
  3. 除了使用 WSDL2Java 工具之外,还有其他方法可以生成代码吗?也许 wsimport 在另一个选项中.利弊是什么?
  4. 有人可以发送一些关于这些主题的优秀教程的链接吗?
  5. 在使用 WSDL2Java 生成代码时,我们需要使用哪些选项?
  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 wsimport in 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?

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

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

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

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

What is the best approach to do this JAVA?

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

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

  1. 我不喜欢它的架构,讨厌它的适得其反的部署模型.
  2. 我发现它是低质量的项目.
  3. 我不喜欢它的性能(参见这个基准JAX-WS RI).
  4. 设置依赖项总是一场噩梦(我使用 Maven,我总是必须与无数的依赖项作斗争)(参见 #2)
  5. Axis 花了很多时间,Axis2 也好不到哪里去.不,这不是个人意见,有共识.
  6. 我受过一次苦,再也没有受过.
  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 always have 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.

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

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.

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

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

做什么?

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

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?

是的!首选 JAX-WS 堆栈,如 CXFJAX-WS RI(您还可以阅读有关 Metro、Metro = JAX-WS RI + WSIT),它们只是更优雅、更简单、更易于使用.在您的情况下,我将只使用 Java 6 中包含的 JAX-WS RI,因此 wsimport.

Yes! Prefer a JAX-WS stack like CXF or 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.

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

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

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

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

  • Developing JAX-WS Web Service Clients (start here)
  • Introducing JAX-WS 2.0 With the Java SE 6 Platform, Part 1
  • Creating a Simple Web Service and Client with JAX-WS
  • Creating a SOAP client with either Apache CXF or GlassFish Metro (Glen Mazza's blog is a great resources)

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

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

没有选项,使用 wsimport :)

No options, use wsimport :)

  • Elad’s Adventures in Java WebServiceLand
  • Axis2: Why bother? on the BileBlog (be prepared for the bile) - you'll have to stop the redirect.