0

当调用尝试运行使用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>

参数类是这样声明的。这些属性只是标准的字符串 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的东西,更重要的是我该如何解决它?

4

1 回答 1

1

原来答案很简单。一旦我想通了。我不得不更改@XmlType(name="",并添加标签的名称。

所以现在参数类的定义如下:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "IsValidEmployerByFein",
         propOrder = { "fein", "username", "password" })
@XmlRootElement(name = "IsValidEmployerByFein")
public class IsValidEmployerByFein
于 2013-09-06T22:02:34.710 回答