提问人:mcs130 提问时间:11/6/2023 最后编辑:mcs130 更新时间:11/6/2023 访问量:37
Wildfly 27 服务器 - 简单的 JAX-WS 部署 - 部署/启动工作 - SOAP 调用导致错误“unmarshall 错误”
Wildfly 27 Server - Simple JAX-WS deployment - Deployment/Startup works - SOAP call results in Fault "unmarshall error"
问:
我最近发布了一个问题,现在通过从 WildFly 23 升级到 27 解决了这个问题,其中部署了简单的 JAX-WS 端点,您可以在日志中看到启动,并且 WSDL URL 响应了预期的 WSDL。原始帖子与部署问题
现在,在解决了部署问题之后,我使用 POSTMAN 从 WildFly 托管的端点导入 WSDL。它加载正常,并且正确显示 2 个操作。
SOAP 消息从 POSTMAN 发送到服务器
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getEmployee xmlns="http://ws.jaxws.example.com/">
<arg0>100</arg0>
</getEmployee>
</soap:Body>
</soap:Envelope>
我得到以下带有错误的响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element (uri:"http://ws.jaxws.example.com/", local:"arg0"). Expected elements are <{}arg0> </faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
WSDL:(来自已部署的服务)
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.jaxws.example.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="EmployeeService" targetNamespace="http://ws.jaxws.example.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws.jaxws.example.com/" elementFormDefault="unqualified" targetNamespace="http://ws.jaxws.example.com/" version="1.0">
<xs:element name="Employee" type="tns:employee"/>
<xs:element name="addEmployee" type="tns:addEmployee"/>
<xs:element name="addEmployeeResponse" type="tns:addEmployeeResponse"/>
<xs:element name="getEmployee" type="tns:getEmployee"/>
<xs:element name="getEmployeeResponse" type="tns:getEmployeeResponse"/>
<xs:complexType name="addEmployee">
<xs:sequence>
<xs:element name="arg0" type="xs:int"/>
<xs:element minOccurs="0" name="arg1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addEmployeeResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:employee"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="employee">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getEmployee">
<xs:sequence>
<xs:element form="qualified" name="id" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getEmployeeResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:employee"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="addEmployee">
<wsdl:part element="tns:addEmployee" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="getEmployeeResponse">
<wsdl:part element="tns:getEmployeeResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="addEmployeeResponse">
<wsdl:part element="tns:addEmployeeResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="getEmployee">
<wsdl:part element="tns:getEmployee" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="EmployeeService">
<wsdl:operation name="addEmployee">
<wsdl:input message="tns:addEmployee" name="addEmployee"> </wsdl:input>
<wsdl:output message="tns:addEmployeeResponse" name="addEmployeeResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:operation name="getEmployee">
<wsdl:input message="tns:getEmployee" name="getEmployee"> </wsdl:input>
<wsdl:output message="tns:getEmployeeResponse" name="getEmployeeResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="EmployeeServiceSoapBinding" type="tns:EmployeeService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="addEmployee">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="addEmployee">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="addEmployeeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getEmployee">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getEmployee">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getEmployeeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="EmployeeService">
<wsdl:port binding="tns:EmployeeServiceSoapBinding" name="EmployeeServiceImplPort">
<soap:address location="http://localhost:8080/employee-service/EmployeeService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
“Employee”的 JAXB 注解类如下所示:
package com.example.jaxws.ws;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
@XmlRootElement(name = "Employee")
@XmlType()
public class Employee {
private static final long serialVersionUID = 1L;
private int id;
private String name;
public Employee() {
}
public Employee(int id, String name) {
this.id = id;
this.name = name;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
服务实现和接口如下所示:
package com.example.jaxws.ws;
import jakarta.jws.WebMethod;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import java.util.UUID;
@WebService(serviceName = "EmployeeService", endpointInterface = "com.example.jaxws.ws.EmployeeService")
@SOAPBinding(style= SOAPBinding.Style.DOCUMENT)
public class EmployeeServiceImpl implements EmployeeService {
private static final Logger logger = LogManager.getLogger(EmployeeServiceImpl.class);
@WebMethod
@WebResult(name = "Employee")
public Employee getEmployee(@WebParam(name = "id", targetNamespace = "http://ws.jaxws.example.com/") int id) {
String txid = UUID.randomUUID().toString();
ThreadContext.put("txid", txid);
Employee employee = new Employee(id, "Smith");
logger.info("Employee: [] returned", employee.toString());
return null;
}
@WebMethod
public Employee addEmployee(int id, String name) {
return new Employee(id, name);
}
}
接口:
package com.example.jaxws.ws;
import jakarta.jws.WebMethod;
import jakarta.jws.WebParam;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style= SOAPBinding.Style.DOCUMENT)
public interface EmployeeService {
@WebMethod
public Employee getEmployee(@WebParam(name = "id", targetNamespace = "http://ws.jaxws.example.com/") int id);
@WebMethod
Employee addEmployee(int id, String name);
}
生成了 WSDL。我已经运行了 wsconsume 来查看它会为客户端调用生成哪些类(但我最终使用 POSTMAN 只是为了在服务端进行基本的测试调用)。
在代码生成过程中没有看到任何错误,我得到了一个装满代码的文件夹:
我试图理解为什么返回错误。
答: 暂无答案
评论