问题描述
我是Java Webservices的新手,目前我正在尝试创建一个简单的基于SOAP的Web服务,但是在创建它时会遇到问题。
I am new to Java Webservices, currently I am trying to create a simple SOAP based web-services but getting issue in creating it.
这是我的webservice类:
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"; }
}
正如你所看到的,我在这里有3种方法。现在如果我只是保持 getDummyTeams
,并要求eclipse创建一个WebService,那么我没有问题。但是当我尝试添加剩下的两个方法 public Team getTeam(String name)
& public List< Team> getTeams()
然后在创建webservice时我收到错误:
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 :
这是我的团队
class:
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
}
你能帮我解决这个问题吗?我想使用 java.util.List
。在创建基于SOAP的Web服务时,是否有任何需要更改eclipse以使用集合的设置?
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?
推荐答案
这不是一个直接回应这个问题。但是我想指出,您可能会考虑不使用JAX-RPC。
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是一个旧的API ,已被JAX-WS替代。
这导致我们问题什么是RPC编码的 strong> WSDL样式?
WSDL文件包含Web服务方法的定义。有四种方式来定义这些方法:
The WSDL file contains the definition of the methods of your webservice. And there are 4 ways/styles to define these methods:
- RPC /编码
- RPC /文字/文字
- 文件/编码
- 文件/文字
- RPC/encoded
- RPC/literal
- Document/encoded
- Document/literal
最重要的一个是以下说明:
Each style has advantages and disadvantages. The most important one is the following remark:
WS-I代表webservice互操作性。所以,正如报价所说明的那样,尽管JAX-RPC支持RPC /编码的WSDL文件,但并不意味着它与其他RPC /编码技术(例如用PHP编写的webservices)兼容。 Java和PHP之间的JAX-RPC Web服务首先可能会起作用,但有时在具体情况下会有所突破。所以教训是:避免RPC /编码的WSDL文件。这就是为什么JAX-WS不支持它们。
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.
不幸的是,有时候您没有选择(例如另一家公司提供webservice)如果是RPC /编码的WSDL文件,那么您将无法使用JAX-WS。 如果托管的Web服务也是用Java编写的,那么您可能冒着使用JAX-RPC的风险。如果是使用其他语言编写的话,那么我不会冒险。在这种情况下,你最好编写一个自定义处理程序。 (您仍然可以安全地使用JAXB(Java Xml Binding)使用注释来执行(un)编组(从/转换到/ xml),就像JAX-WS webservices一样。)
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文件?您只需在文本编辑器中打开它,并查找绑定标签。以下示例是RPC /文字样式的WSDL文件。所以你可以使用这个webservice的JAX-WS。
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>
当您定义自己的Web服务时,可以使用<$ c注释您的课程来选择WSDL样式$ c> @SOAPBinding(style = Style.RPC,use = Use.LITERAL)。
When you define your own webservice, you can choose the WSDL style by annotating your class with @SOAPBinding(style=Style.RPC, use=Use.LITERAL)
.
混乱的来源: / strong> JAX-RPC和JAX-WS都使用SOAP。还有一个名为 XML-RPC
的东西,这是一个旧的标准(SOAP之前)。 但是JAX-RPC不使用 XML-RPC
。另一方面,SOAP有时被称为基于XML 的 RPC。
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".
这篇关于服务类别不符合JAX-RPC 1.1规范的一个或多个要求,可能不会部署或正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!