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

前端 未结 5 480
傲寒
傲寒 2021-01-19 04:51

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:

相关标签:
5条回答
  • 2021-01-19 05:35

    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.

    0 讨论(0)
  • 2021-01-19 05:36

    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

    0 讨论(0)
  • 2021-01-19 05:39

    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.

    0 讨论(0)
  • 2021-01-19 05:40

    JAX-RPC 1.1 spec provides something called pluggable serializers and deserializers to support collection classes.

    0 讨论(0)
  • 2021-01-19 05:50

    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".

    0 讨论(0)
提交回复
热议问题