javax.xml.bind.UnmarshalException: unexpected element (uri: " " , local: "arg0" )。预期的元素是<{}客户信息&g



我面临这个问题2天,但无法解决这个问题。我正在尝试使用JAX-WS调用web服务。服务调用,但其中的对象未被解析。

            JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
            factory.setServiceClass(ICustomer.class);
            factory.setAddress("http://localhost:8080/backend/services/CustomerInfo");
            ICustomer client = (ICustomer) factory.create();
            // Below is the service call. where 'object' is my CustomerInfo object/data
            client.saveCustomer(object);

服务实现类:

@WebService(endpointInterface = "com.dev.backend.services.interfaces.ICustomer", serviceName="CustomerInfo")
public class ICustomerImpl implements ICustomer {
public boolean saveCustomer(Object object) {
    JAXBContext payloadContext;
    try {
        payloadContext = JAXBContext.newInstance(CustomerInfo.class);
        CustomerInfo o = (CustomerInfo)payloadContext.createUnmarshaller().unmarshal((Node)object); // Line 'error'
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

(CustomerInfo)payloadContext.createUnmarshaller(). unmarshaller ((Node)object)是异常抛出"javax.xml.bind. xml"的行。UnmarshalException:意外元素(uri:", local:"arg0")。期望的元素是<{}customerInfo>"

有谁能帮帮我吗?我正在寻找解决方案2天。

谢谢

您有这样的XML节点吗?

<ws:customerInfo> ... </ws:customerInfo>

如果有,请尝试删除"ws"

更新:如果你有一个类似这样的方法:

public ReturnType Method1(
            @WebParam(name="RequestType1") RequestType1 request)

尝试将其更改为:

public ReturnType Method1(
                @WebParam(name="requestType1") RequestType1 request)

注意,两种情况下的webParam名称是不同的。RequestType1是一个类,webParam的名称也相同。name参数类似于实例名,如果与类名相同,则会被误解。

相关内容

最新更新