eclipse 服务类不符合 JAX-RPC 1.1 规范的一项或多项要求,可能无法正确部署或运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30606020/
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
The service class does not comply to one or more requirements of the JAX-RPC 1.1 specification, and may not deploy or function correctly
提问by learner
I am new to Java Webservices, currently I am trying to create a simple SOAP based web-services but getting issue in creating it.
我是 Java Webservices 的新手,目前我正在尝试创建一个简单的基于 SOAP 的 Web 服务,但在创建它时遇到了问题。
Here is my webservice class:
这是我的网络服务类:
@WebService
public class Teams {
private TeamsUtility utils;
public Teams() {
utils = new TeamsUtility();
utils.make_test_teams();
}
@WebMethod
public Team getTeam(String name) { return utils.getTeam(name); }
@WebMethod
public List<Team> getTeams() { return utils.getTeams(); }
@WebMethod
public String getDummyTeams() { return "Hi"; }
}
As you can see I have 3 methods here. Now if I just keep getDummyTeams
and ask eclipse to create a WebService, then I have no issues. But when I tried to add remaining 2 methods public Team getTeam(String name)
& public List<Team> getTeams()
then while creating webservice I am getting error as :
如您所见,我在这里有 3 种方法。现在,如果我只是保持getDummyTeams
并要求 eclipse 创建一个 WebService,那么我就没有问题。但是,当我尝试添加剩余的 2 种方法时public Team getTeam(String name)
,public List<Team> getTeams()
然后在创建 Web 服务时出现以下错误:
The service class "helloservice.endpoint.Teams" does not comply to one or more requirements of the JAX-RPC 1.1 specification, and may not deploy or function correctly. The field or property "players" on the value type "helloservice.endpoint.Team" used via the service class "helloservice.endpoint.Teams" has a data type, "java.util.List", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.
服务类“helloservice.endpoint.Teams”不符合 JAX-RPC 1.1 规范的一项或多项要求,可能无法正确部署或正常运行。通过服务类“helloservice.endpoint.Teams”使用的值类型“helloservice.endpoint.Team”上的字段或属性“players”具有 JAX 不支持的数据类型“java.util.List” -RPC 1.1 规范。该类型的实例可能无法正确序列化或反序列化。可能会导致数据丢失或 Web 服务完全失败。
Here is my Team
class:
这是我的Team
课:
@XmlRootElement
public class Team implements Serializable{
private List<Player> players;
private String name;
public Team() {
}
public Team(String name, List<Player> players) {
setName(name);
setPlayers(players);
}
// Setter & Getter methods
}
Can you please help me how do I fix this issue? I want to use java.util.List
. Is there any settings I have to change in eclipse to use collections while creating SOAP based web-services?
你能帮我解决这个问题吗?我想用java.util.List
. 在创建基于 SOAP 的 Web 服务时,我是否必须在 Eclipse 中更改任何设置才能使用集合?
回答by bvdb
This is not a direct response to the question. But nevertheless I would like to point out that you may consider not to use JAX-RPC at all.
这不是对问题的直接回答。不过我想指出的是,您可能会考虑根本不使用 JAX-RPC。
First of all, JAX-RPC is an old API, which has been replaced with JAX-WS.
首先,JAX-RPC 是一个旧的 API,它已经被 JAX-WS 取代了。
Reasons you may want to stay with JAX-RPC 1.1: ... If you want to send SOAP encoded messages or create RPC/encoded style WSDL.
您可能希望继续使用 JAX-RPC 1.1 的原因:...如果您想发送 SOAP 编码的消息或创建 RPC/编码样式的 WSDL。
And that leads us to the question "what is an RPC-encodedWSDL style?"
这就引出了一个问题“什么是RPC 编码的WSDL 风格?”
The WSDL file contains the definition of the methods of your webservice. And there are 4 ways/styles to define these methods:
WSDL 文件包含 Web 服务方法的定义。并且有 4 种方式/样式来定义这些方法:
- RPC/encoded
- RPC/literal
- Document/encoded
- Document/literal
- RPC/编码
- RPC/文字
- 文件/编码
- 文档/文字
Each style has advantages and disadvantages.The most important one is the following remark:
每种风格都有优点和缺点。最重要的是下面的一句话:
Although it is legal WSDL, RPC/encoded is not WS-I compliant.
尽管它是合法的 WSDL,但 RPC/encoded 不符合 WS-I。
WS-I stands for "webservice interoperability". So, as the quote clarifies, even though JAX-RPC supports RPC/encoded WSDL files, that doesn't mean it's compatible with other RPC/encoded technologies (e.g. webservices written in PHP). JAX-RPC webservices between Java and PHP may seem to work at first, but will sometimes break in specific cases. So the lesson is: avoid RPC/encoded WSDL files.And that's exactly why JAX-WS doesn't support them.
WS-I 代表“网络服务互操作性”。因此,正如引用所阐明的那样,即使 JAX-RPC 支持 RPC/编码的 WSDL 文件,这并不意味着它与其他 RPC/编码的技术(例如用 PHP 编写的 Web 服务)兼容。Java 和 PHP 之间的 JAX-RPC Web 服务起初似乎可以工作,但有时在特定情况下会中断。所以教训是:避免使用 RPC/编码的 WSDL 文件。这正是 JAX-WS 不支持它们的原因。
Unfortunately, sometimes you don't have a choice (e.g. another company provides the webservice) If it's a RPC/encoded WSDL file, then you won't be able to use JAX-WS. If the hosted webservice is also written in Java, then you could risk using JAX-RPC. If it's written in some other language, then I wouldn't take the risk. You're better of writing a custom handler when that happens. (You can still safely use JAXB (Java Xml Binding) to perform the (un)marshalling (conversion from/to xml) using annotations, just like with JAX-WS webservices.)
不幸的是,有时您没有选择(例如另一家公司提供网络服务)。如果它是 RPC/编码的 WSDL 文件,那么您将无法使用 JAX-WS。如果托管的 Web 服务也是用 Java 编写的,那么您可能会冒着使用 JAX-RPC 的风险。如果它是用其他语言编写的,那么我不会冒险。发生这种情况时,您最好编写自定义处理程序。(您仍然可以安全地使用 JAXB(Java Xml 绑定)使用注释来执行(取消)编组(从/到 xml 的转换),就像使用 JAX-WS Web 服务一样。)
But how do you know if it's an RPC/encoded WSDL file? You just open it in a text editor, and look for the binding tag. The following example is an RPC/literal style WSDL file. So you can use JAX-WS with this webservice.
但是你怎么知道它是否是一个 RPC/编码的 WSDL 文件?您只需在文本编辑器中打开它,然后查找绑定标签。以下示例是一个 RPC/文字样式 WSDL 文件。因此,您可以将此 Web 服务与 JAX-WS 一起使用。
<binding name="MyService" type="tns:MyService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="method">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" .../>
</input>
<output>
<soap:body use="literal" .../>
</output>
</operation>
</binding>
When you define your own webservice, you can choose the WSDL style by annotating your class with @SOAPBinding(style=Style.RPC, use=Use.LITERAL)
.
当您定义自己的 Web 服务时,您可以通过使用@SOAPBinding(style=Style.RPC, use=Use.LITERAL)
.
A source of confusion:both JAX-RPC and JAX-WS use SOAP. There's also a thing called XML-RPC
which is an old standard (before SOAP). But JAX-RPC does not use XML-RPC
.On the other hand, SOAP is sometimes called "XML basedRPC".
混淆的根源:JAX-RPC 和 JAX-WS 都使用 SOAP。还有一种叫做XML-RPC
旧标准的东西(在 SOAP 之前)。但是 JAX-RPC 不使用XML-RPC
. 另一方面,SOAP 有时也称为“基于XML的RPC”。
回答by Shashikant Patil
JAX-RPC 1.1 spec does not specify a clear mapping between the java.util.List object and XML.since you are returning java.util.List type.
JAX-RPC 1.1 规范没有在 java.util.List 对象和 XML. 之间指定明确的映射,因为您返回的是 java.util.List 类型。
change your method like
改变你的方法
public Team[] getTeams() { return utils.getTeams(); }
And your getTeams()
implementation should be match with this.
你的getTeams()
实现应该与此匹配。
回答by Amit.rk3
回答by Amol Binwade
The primary reason why the collection classes are not standardized for use in Java Web services is that they are loosely typed collections. In the absence of significant additional data from the user, it is not possible to map a Java collection to a well-defined Schema and clear rules to the runtime for serializing and deserializing elements of the collection.
集合类没有标准化以用于 Java Web 服务的主要原因是它们是松散类型的集合。在没有来自用户的重要附加数据的情况下,不可能将 Java 集合映射到定义良好的 Schema 并为运行时明确规则以对集合的元素进行序列化和反序列化。
Use Java arrays instead of collections to represent sequences of elements in WSDL. Java arrays are strongly typed and, as a result, map to and from strongly-typed Schema, yielding interoperable WSDL and SOAP traffic with clear rules for deserialization and serialization to and from Java. See link.
使用 Java 数组而不是集合来表示 WSDL 中的元素序列。Java 数组是强类型的,因此,映射到强类型模式和从强类型模式映射,产生可互操作的 WSDL 和 SOAP 流量,具有明确的反序列化和序列化规则,用于与 Java 之间的反序列化和序列化。见链接。
回答by Amol Binwade
JAX-RPC 1.1 spec provides something called pluggable serializers and deserializers to support collection classes.
JAX-RPC 1.1 规范提供了一种称为可插入序列化器和反序列化器的东西来支持集合类。