簡體   English   中英

CXF JAX-WS無法將參數發送到Web服務

[英]CXF JAX-WS Unable send parameter to Web Service

當調用嘗試運行由wsdl2java生成的CXF客戶端時,出現以下異常: com.sun.istack.SAXException2: Instance of "us.ak.state.labor.service.IsValidEmployerByFein" is substituting "java.lang.Object", but "us.ak.state.labor.service.IsValidEmployerByFein" is bound to an anonymous type.

我可以使用SoapUI成功運行WebService。

WSDL的相關部分如下所示:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
                  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
                  xmlns:tns="http://tempuri.org/EmployerService/Service"
                  xmlns:s="http://www.w3.org/2001/XMLSchema"
                  xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
                  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
                  targetNamespace="http://tempuri.org/EmployerService/Service"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified"
              targetNamespace="http://tempuri.org/EmployerService/Service">
      <s:element name="IsValidEmployerByFein">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="FEIN" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="IsValidEmployerByFeinResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1"
                       name="IsValidEmployerByFeinResult">
              <s:complexType mixed="true">
                <s:sequence>
                  <s:any />
                </s:sequence>
              </s:complexType>
            </s:element>
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="IsValidEmployerByFeinSoapIn">
    <wsdl:part name="parameters" element="tns:IsValidEmployerByFein" />
  </wsdl:message>
  <wsdl:message name="IsValidEmployerByFeinSoapOut">
    <wsdl:part name="parameters" element="tns:IsValidEmployerByFeinResponse" />
  </wsdl:message>
  <wsdl:portType name="ServiceSoap">
    <wsdl:operation name="IsValidEmployerByFein">
      <wsdl:input message="tns:IsValidEmployerByFeinSoapIn" />
      <wsdl:output message="tns:IsValidEmployerByFeinSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="IsValidEmployerByFein">
      <soap:operation style="document"
        soapAction="http://tempuri.org/EmployerService/Service/IsValidEmployerByFein"/>
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="IsValidEmployerByFein">
      <soap12:operation style="document"
        soapAction="http://tempuri.org/EmployerService/Service/IsValidEmployerByFein"/>
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Service">
    <wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">
      <soap:address location="https://my.server.name/EmployerService/Service.asmx" />
    </wsdl:port>
    <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">
      <soap12:address location="https://my.server.name/EmployerService/Service.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

像這樣聲明參數類。 這些屬性只是標准的String getter / setter。

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "fein", "username", "password" })
@XmlRootElement(name = "IsValidEmployerByFein")
public class IsValidEmployerByFein

我的ServiceSoap接口定義了如下方法:

@WebService(targetNamespace = "http://tempuri.org/EmployerService/Service",
            name = "ServiceSoap")
@XmlSeeAlso({ObjectFactory.class})
public interface ServiceSoap
{
  @WebResult(name = "IsValidEmployerByFeinResult",
             targetNamespace = "http://tempuri.org/EmployerService/Service")
  @RequestWrapper(localName = "IsValidEmployerByFein",
                  targetNamespace = "http://tempuri.org/EmployerService/Service",
                  className = "us.ak.state.labor.service.IsValidEmployerByFein")
  @WebMethod(operationName = "IsValidEmployerByFein",
             action = "http://tempuri.org/EmployerService/Service/IsValidEmployerByFein")
  @ResponseWrapper(localName = "IsValidEmployerByFeinResponse",
                   targetNamespace = "http://tempuri.org/EmployerService/Service",
                   className = "us.ak.state.labor.service.isValidEmployerByFein.IsValidEmployerByFeinType")
  public IsValidEmployerByFeinType isValidEmployerByFein(
         @WebParam(name = "FEIN",
                   targetNamespace = "http://tempuri.org/EmployerService/Service")
         String fein,
         @WebParam(name = "Username",
                   targetNamespace = "http://tempuri.org/EmployerService/Service")
         String username,
         @WebParam(name = "Password",
                   targetNamespace = "http://tempuri.org/EmployerService/Service")
         String password
         );

和我的ObjectFactory

@XmlRegistry
public class ObjectFactory
{
   public IsValidEmployerByFein createIsValidEmployerByFein()
   { return new IsValidEmployerByFein(); }

因此,這就是一切的定義方式; 為什么我得到一個SAXException2 ,它不能替代IsValidEmployerByFein ,更重要的是如何解決它?

原來答案很簡單。 一旦我想通了。 我必須更改@XmlType(name="",並添加標簽的名稱。

現在,參數類的定義如下:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "IsValidEmployerByFein",
         propOrder = { "fein", "username", "password" })
@XmlRootElement(name = "IsValidEmployerByFein")
public class IsValidEmployerByFein

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM