javax.xml.bind.UnmarshalException:意外元素(uri:"",local:" arg0")。预期元素是< {} customerInfo>

时间:2015-07-25 08:59:45

标签: java xml web-services jaxb cxf

我面临这个问题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:意外元素(uri:"" ,local:" arg0")。预期元素是< {} customerInfo>"

请帮助我。我正在寻找解决方案2天。

由于

1 个答案:

答案 0 :(得分: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参数类似于实例名称,如果两者都相同,则会被类名误解。

相关问题