javax.xml.bind.UnmarshalException:意外元素(uri:“”,local:“arg0”)。预期的要素是

问题描述 投票:1回答:1

我面临这个问题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()。unmarshal((Node)object)是异常抛出的行“javax.xml.bind.UnmarshalException:unexpected element(uri:”“,local:”arg0“)。预期的元素是< {} customerInfo>”

可以请任何帮助我。我正在寻找解决方案2天。

谢谢

java xml web-services jaxb cxf
1个回答
0
投票

你有这样的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参数类似于实例名称,如果两者相同,则会被类名误解。

© www.soinside.com 2019 - 2024. All rights reserved.