Axis2 Web 服务客户端生成 - 无需修改客户端的类型
是否可以使用 Axis2 和 Eclipse 生成 Web 服务客户端并让它使用包中已有的 java 类型,而不是创建它自己的类型。 当然,原因是如果我已经创建了类型 A 并且它创建了自己的类型 AI,则不能仅将类型 A 的变量分配给类型 B 的变量。
wsdl 是从部署到应用程序服务器的 Web 服务生成的。 如果无法从中生成它,则可以从现有的 java 文件生成客户端。
Is it possible with Axis2 and Eclipse to generate a Web Service client and have it use java types that you already have in packages instead of creating it's own types. Reason being of course if I have type A already created and it creates it's own Type A I can't just assign variable of type A to variable of type B.
The wsdl is being generated from a Web Service deployed to an application server.
If it's not possible to generate it from that would it be possible to generate a client from the already existing java files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您确实想重用现有的类,可以直接调用Axis2 API,而无需使用wsdl2java生成客户端。 下面是一些调用 Web 服务的相对简单的代码。 您只需填写 Web 服务端点、方法 QName、预期返回类和服务参数。 您可以重用现有的类作为返回值或参数。
如果您的 Web 服务非常复杂,那么您可能会发现必须深入了解 API 才能使这种方法发挥作用。
If you really want to reuse existing classes, you can call the Axis2 API directly without generating a client using wsdl2java. Below is some relatively simple code to call a web service. You just need to fill in the web service endpoint, method QName, expected return Class(es), and arguments to the service. You could reuse your existing classes as the return values or arguments.
If your web service is pretty complicated then you may find that you have to go deeper into the API to get this approach to work.
您正在从 wsdl 生成 Web 服务客户端,对吗?
wsdl2java 工具唯一了解的是 wsdl 中的信息,因此它不会了解您已创建的任何类型。
如果您可以将类型信息放入 wsdl 中,您就可以让它工作,尽管我从未尝试过。
如果您想要一种简单的方法从 A 型复制到 B 型,那么您可以尝试 BeanUtils.copyProperties,只要A类型和B类型的setter和getter匹配。
You are generating the web service client from wsdl, correct?
The only thing that the wsdl2java tool knows about is the information in the wsdl, so it won't know about any types that you have already created.
If you can get the type information into the wsdl you may get it to work, although I have never tried.
If you want an easy way to copy from Type A to Type B then you could try BeanUtils.copyProperties, as long as the setters and getters of Type A and Type B match.
几乎大多数 Java Web 服务项目都会经历这个过程。 我不知道.NET/C#世界是否有更优雅的解决方案。
正如 Mike 提到的,使用 BeanUtils.copyProperties 是有意义的。
BR,
~A
pretty much most java webservices projects go through this. I don't know if the .NET/C# world have a more elegant solution.
It makes sense, as Mike mentioned, to use BeanUtils.copyProperties.
BR,
~A
如果您使用 Eclipse 作为 IDE,那么您需要的是: http://www.eclipse.org/webtools /。 它所做的超出了其他事情,正是您想要的。
If you use eclipse as your ide, that is waht you need: http://www.eclipse.org/webtools/. It does beyond other things exactly what you want.
您可以直接使用ServiceClient类来调用Web服务,它仅使用XML提供调用并返回XML响应。 对于不同的Web服务方法,您必须将XML响应转换为一些java POJO才能使用它。 您只需完成响应处理。 你可以像从 XML 到 Map 等那样做...
所以你不需要任何其他存根类来调用任何 Web 服务,只需要处理响应 XML。 您可以使用 Castor 或 JAXB 库将 XML 转换为 POJO。
这样你就不需要每次都修改你的客户端来进行 diff。 网页服务。 您可以像在外部向客户端提供响应处理程序一样进行开发。 因此,对于每个不同的网络服务,您都会有差异。 响应处理程序类是您接口的实现。
参考:
http://www.developer.com/java/web/article.php/3863416/Using-Axis2-and-Java-for-Asynchronous-Web-Service-Inspiration- on-the-Client-Side.htm
http://www.devdaily.com/blog/post/java/java-web-service-client-read-array-list/
谢谢。
www.techlads.com
You can directly use ServiceClient class to call web service, which provides call using XML only and returns XML response. For different methods of web service, you have to convert the XML response to some java POJO to use it. Only Response handling needs to be done at your end. that you can do like from XML to Map etc...
So you won't need any other stub classes to call any web service, only needs to handle response XML. You can convert XML to POJO using Castor or JAXB libs.
This is the way you don't need to modify your client every time for diff. web services. You can develop like providing a response handler to client externally. So that for every different web service you will have diff. response handler class which is implementation of you interface.
reference:
http://www.developer.com/java/web/article.php/3863416/Using-Axis2-and-Java-for-Asynchronous-Web-Service-Invocation-on-the-Client-Side.htm
http://www.devdaily.com/blog/post/java/java-web-service-client-read-array-list/
thanks.
www.techlads.com
如果这篇文章对某人仍然有用,我阅读了 axis2 生成客户端指南: http://axis.apache.org/axis2/java/core/docs/userguide-creatingclients.html。
Axis2 Eclipse 插件似乎配置为以集成模式调用 ADB 代码生成(请参阅 http://axis.apache.org/axis2/java/core/docs/adb/adb-howto.html),从而在 Web 服务存根中创建内部类。 我不知道是否可以将生成模式更改为扩展模式(从存根类生成数据类),但您可以使用 Wsdl2Java 命令行执行此操作:
-u 选项告诉 ADB 代码生成器创建数据类为存根中的单独类而不是内部类。
In case this post is still of any use to someone I read the axis2 generating clients guide: http://axis.apache.org/axis2/java/core/docs/userguide-creatingclients.html.
It seems that the Axis2 Eclipse plugin is configured to call ADB code generation in integrated mode (see http://axis.apache.org/axis2/java/core/docs/adb/adb-howto.html), thus creating inner classes in the Web service stub. I don't know if changing the generation mode to expanded mode (generate data classes out of the stub class) is possible, but you can do it command line using Wsdl2Java:
The -u option tells the ADB code generator to create data classes as separate classes and not inner classes in the stub.