首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反序列化操作的请求消息正文时出现JAX-WS错误

反序列化操作的请求消息正文时出现JAX-WS错误
EN

Stack Overflow用户
提问于 2013-07-01 22:30:47
回答 1查看 2.6K关注 0票数 1

根据this教程,我使用Aramex API来计算产品的运费,从而创建一个web服务。下面是我的测试类:

代码语言:javascript
复制
package com.test;

import net.aramex.ws.shippingapi.v1.*;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceRef;
import java.net.URL;

public class AramexRateCalculatorClient {

@WebServiceRef(wsdlLocation = "C:\\aramex-rates-calculator-wsdl.wsdl")
private static Service10_Service service;

public static void main(String [] args) {

    try {

    service = new Service10_Service();

    RateCalculatorRequest request = new RateCalculatorRequest();
    ClientInfo clientInfo = new ClientInfo();
    clientInfo.setUserName("mymail@gmail.com");
    clientInfo.setPassword("abcd1234");
    clientInfo.setVersion("v1.0");

    Transaction transaction = new Transaction();
    transaction.setReference1("001");

    Address orgAddress = new Address();
    orgAddress.setCity("Amman");
    orgAddress.setCountryCode("JO");

    Address dstAddress = new Address();
    dstAddress.setCity("Dubai");
    dstAddress.setCountryCode("AE");

    ShipmentDetails shipmentDetails = new ShipmentDetails();
    shipmentDetails.setPaymentType("P");
    shipmentDetails.setProductGroup("EXP");
    shipmentDetails.setProductType("PPX");

    Weight weight = new Weight();
    weight.setUnit("KG");
    weight.setValue(5);
    Weight cweight = new Weight();
    cweight.setUnit("KG");
    cweight.setValue(5);
    shipmentDetails.setActualWeight(weight);
    shipmentDetails.setChargeableWeight(cweight);
    shipmentDetails.setNumberOfPieces(5);

    JAXBElement<ClientInfo>  jaxbElementClientInfo = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , ClientInfo.class , clientInfo);
    request.setClientInfo(jaxbElementClientInfo);

    JAXBElement<Transaction>  jaxbElementTransaction = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , Transaction.class , transaction);
    request.setTransaction(jaxbElementTransaction);

    JAXBElement<Address>  jaxbElementorgAddress = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , Address.class , orgAddress);
    request.setOriginAddress(jaxbElementorgAddress);

    JAXBElement<Address>  jaxbElementDstAddress = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , Address.class , dstAddress);
    request.setDestinationAddress(jaxbElementDstAddress);

    JAXBElement<ShipmentDetails>  jaxbElementShipmentDetails = new JAXBElement(new QName("http://ws.aramex.net/ShippingAPI/v1/") , ShipmentDetails.class , shipmentDetails);
    request.setShipmentDetails(jaxbElementShipmentDetails);


    RateCalculatorResponse response = service.getService10().calculateRate(request);
    System.out.println("success");

    } catch (Exception ex) {
        System.out.println(ex);
    }
  }
}

当我运行我的main方法时,它给了我以下异常(当调用calculateRate方法时):

代码语言:javascript
复制
com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'CalculateRate'. Name cannot begin with the '/' character, hexadecimal value 0x2F. Line 1, position 244. Please see the server log to find more detail regarding exact cause of the failure.
    at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:134)
    at com.sun.xml.ws.client.sei.StubHandler.readResponse(StubHandler.java:252)
    at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:181)
    at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:262)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:128)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
    at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:154)
    at $Proxy35.calculateRate(Unknown Source)
    at com.aeturnum.ajlan.AramexRateCalculatorClient.main(AramexRateCalculatorClient.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

此错误的原因是什么?我如何修复它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-01 22:42:40

您使用的QName是错误的。单参数构造函数不接受命名空间,它接受元素的“本地名称”。您需要使用其他构造函数之一。

要自己发现这个问题,一种方法是检查测试代码生成的xml请求。您应该熟悉这一点,因为在调试webservice调用的问题时,经常需要检查实际的请求和响应。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17406944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档