将DateTime响应映射到java.util.Date(而不是SoapPrimitive)

时间:2012-05-07 20:49:20

标签: ksoap2 android-ksoap2

我在从Date响应中获取java.util.Dateksoap2)对象时遇到问题。这是响应XML:

  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header></s:Header>
    <s:Body>
      <UpdateLocationResponse xmlns="http://tempuri.org/">
        <UpdateLocationResult>2012-05-07T13:34:34.7693883-04:00</UpdateLocationResult>
      </UpdateLocationResponse>
    </s:Body>
  </s:Envelope>

以下是我用于初始化信封和请求的代码(由于安全原因,使用 * * 而不是真实姓名):

static final String NAMESPACE = "http://tempuri.org/";
static final String URL = "http://****************.svc";

envelope.addMapping(NAMESPACE, "UpdateLocationResult", Date.class,
        new MarshalDate());
MarshalDate mdate = new MarshalDate();
mdate.register(envelope);
envelope.implicitTypes = true;

HttpTransportSE trans = new HttpTransportSE(URL);
trans.debug = true;

trans.call(SOAP_ACTION, envelope);
Object r = envelope.getResponse(); // r is always SoapPrimitive!!!
                                   // I want it to be a java.util.Date

我已尝试过命名空间,属性名称和marshallers的所有组合,但无济于事。我总是从SoapPrimitive

返回envelope.getResponse()

我做错了什么?

1 个答案:

答案 0 :(得分:0)

它不是一个字符串吗?尝试使用SimpleDateFormat

这可能对你有用:

SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String strDate = response.toString();