gpt4 book ai didi

java - CXF JAX-WS 无法将参数发送到 Web 服务

转载 作者:行者123 更新时间:2023-12-01 14:09:19 25 4
gpt4 key购买 nike

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

参数类的声明如下。这些属性只是标准的字符串 getters/setters。

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

我的ServiceSoap接口(interface)定义方法如下:

@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

关于java - CXF JAX-WS 无法将参数发送到 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18666070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com