问题
I am new to Java Webservices, currently I am trying to create a simple SOAP based web-services but getting issue in creating it.
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 :
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.
Here is my Team class:
@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?
回答1:
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.
First of all, JAX-RPC is an old API, which has been replaced with 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.
And that leads us to the question "what is an RPC-encoded WSDL style?"
The WSDL file contains the definition of the methods of your webservice. And there are 4 ways/styles to define these methods:
- RPC/encoded
- RPC/literal
- Document/encoded
- Document/literal
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.
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.
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.)
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.
<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).
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 based RPC".
回答2:
I think JAX RPC 1.1 doesn't support List as data type for service bean classes. Use Array instead. you can see this answer for similar issue
回答3:
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.
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.
回答4:
JAX-RPC 1.1 spec provides something called pluggable serializers and deserializers to support collection classes.
回答5:
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.
change your method like
public Team[] getTeams() { return utils.getTeams(); }
And your getTeams() implementation should be match with this.
来源:https://stackoverflow.com/questions/30606020/the-service-class-does-not-comply-to-one-or-more-requirements-of-the-jax-rpc-1-1