在没有 wsimport 的情况下使用 Java 中的通用 xml soap webservice [英] Consuming generic xml soap webservice in Java without wsimport

查看:32
本文介绍了在没有 wsimport 的情况下使用 Java 中的通用 xml soap webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种无需使用 wsimport 和类似工具即可使用 soap 网络服务的方法.到目前为止,我发现的所有内容都需要生成 wsdl 工件,我想避免使用它,因为我不知道将使用哪个 Web 服务.

I'm searching for a way to consume soap webservices without using wsimport and tools like that. So far, everyting I found requires the wsdl artifacts generation and I want to avoid it because I don't know wich webservices will be used.

这个想法是让用户可以添加几个 WSDL 的 url/方法,程序使用它们并将它的响应发送到另一个 url.

The idea is to give the user the possibility to add several WSDL's urls / methods and the program consume them and send it's response to another url.

我不是在寻找开箱即用的解决方案/代码或类似的东西.我需要的是知道这是否可能,以及如何解决这个问题、想法和类似的事情.

I'm not looking for out of the box solutions/code or something like that. What I need is to know if it is possible or not and how to aproach this problem, ideas and things like that.

谢谢!

推荐答案

SOAP 要求客户端和服务器之间签订契约.合同是客户端将给出一个 XYZ 格式的请求 XML,服务器将给出 ABC 格式的响应.没有这个,SOAP 就无法工作.这就是 WSDL 中定义的内容.所以我们必须使用WSDL.

SOAP mandates a contract between the Client and Server. The contract is that Client will give a request XML is XYZ format and Server will give response in ABC format. Without this, SOAP does not work. This is what is defined in WSDL. So we have to use WSDL.

wsimport、wsdl4j 等工具将这些 WSDL 文件转换为对象层次结构,并为您准备一个 JAXB 包装器,让生活变得轻松!

Tools like wsimport, wsdl4j convert these WSDL files into an object hierarchy and prepares a JAXB wrapper for you, to make life easy!

现在,如果您不想使用自动将 WSDL 转换为 Java Bean 或任何此类的工具,请注意 SOAP 仅基于 XML.如果您知道如何在 Java 中解析 XML,那就差不多了.您可以使用 JAX 解析器来实现这一点,并且您可以读取 SOAP 请求和响应中的所有内容.

Now if you do not want to use the tools which automatically convert WSDL to Java Beans or anything of that sort, note SOAP is based on nothing but an XML. If you know how to parse an XML in java, thats pretty much it. You can use a JAX Parser to achieve this and you can read everything that comes in a SOAP request and response.

您将面临的问题是,随着 SOAP XML 的复杂性增加,您将难以正确解析 XML,正确识别节点、值和关系.此外,如果没有适当的对象层次结构,您就无法在相距较远的节点之间建立关联.意思是,从第 100 行开始,您无法返回并关联第 10 行节点,除非您开始维护自己的对象、关系等(我猜这不是您想要的)

The problem that you will face is, as the complexity of the SOAP XML grows, it will be difficult for you to parse the XML properly, identify the nodes, values and relations properly. And add to that the problem where in you cannot, without a proper object hierarchy , relate between nodes which are distance apart. Meaning, from line 100 you cannot go back and relate a line 10 node, unless you start maintaining your own objects, relations etc. (which is not what you want, i guess)

使用 Java Bean 可以维护对象层次结构,因此您可以轻松地将它们轻松关联到不同节点的不同对象之间.但是 JAXB 相对来说比 JAX 慢.

Using Java Beans the object hierarchy is maintained and because of that it is easy for you to relate them between different objects at different nodes easily. But JAXB is comparatively slower than JAX.

这篇关于在没有 wsimport 的情况下使用 Java 中的通用 xml soap webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆