【问题标题】:javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"arg0"). Expected elements are <{}customerInfo>javax.xml.bind.UnmarshalException:意外元素(uri:“”,本地:“arg0”)。预期元素是 <{}customerInfo>
【发布时间】:2015-07-25 08:59:45
【问题描述】:

我遇到此问题 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”)的行。预期元素是 "

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

谢谢

【问题讨论】:

    标签: java xml web-services jaxb cxf


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 2021-08-01
      • 2014-01-02
      • 1970-01-01
      相关资源
      最近更新 更多