简体   繁体   English

SOAP xml作为回报 - Android

[英]SOAP xml in return - Android

I'm using k2SOAP for Android when dealing with webservices. 在处理webservices时,我正在使用k2SOAP for Android。

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ProjectID", 1);

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);

HttpTransportSE httpTransport = new HttpTransportSE(URL);

try {

    httpTransport.call(SOAP_ACTION, soapEnvelope);
    SoapObject result = (SoapObject) soapEnvelope.getResponse();
    String resultString = result.toString();
}

I know there is nothing wrong with the code since it works with the w3 web service. 我知道代码没有任何问题,因为它适用于w3 Web服务。 But w3c returns a string as an answer this web service returns an XML. 但是w3c返回一个字符串作为答案,这个Web服务返回一个XML。 The answer I get back looks like this when I show it in log: 当我在日志中显示时,我得到的答案看起来像这样:

anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType{element=an    yType{complexType=anyType{sequence=anyType{element=anyType{}; 
element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; 
unique=anyType{selector=anyType{}; field=anyType{}; }; }; }; diffgram=anyType{}; }

Which basically is a lot of noise and I'm not sure on how to get the information from this or how I should parse it or. 这基本上是很多噪音,我不知道如何从这里获取信息或我应该如何解析它或。 My ultimate goal is to put the information I get in to a local database but since I don't know how to get the information from the String I don't know put the info in the database. 我的最终目标是将我收到的信息放到本地数据库中,但由于我不知道如何从字符串中获取信息,所以我不知道将信息放在数据库中。

So what I want to do is to somehow parse the information and put it in a local database which I already built the classes for. 所以我想做的是以某种方式解析信息并将其放在我已经构建了类的本地数据库中。 How do I get the data from the SoapObject result? 如何从SoapObject结果中获取数据? There is a slight possibility the web service info is empty, but my question is still the same. Web服务信息很可能是空的,但我的问题仍然是一样的。

Two Things you need to change 你需要改变两件事

1)Add this "httpTransport.setXmlVersionTag("<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>");" 1)添加"httpTransport.setXmlVersionTag("<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>");"

line above "httpTransport.call(SOAP_ACTION, soapEnvelope);" 上面的行"httpTransport.call(SOAP_ACTION, soapEnvelope);"

2) String resultString = result.toString(); 2) String resultString = result.toString();

Replace the above line with following one 将以上行替换为以下行

String resultString=httpTransport.responseDump;

This will return response as xml formated String 这将以xml格式化String返回响应

The provided answer did not work for me rather lines bellow worked for me. 提供的答案对我来说不起作用,而是对我来说有些线索。 Try the following lines, hope this will give you data with XML tags, 请尝试以下几行,希望这将为您提供带有XML标签的数据,

httpTransport.debug=true; 
httpTransport.call(SOAP_ACTION, soapEnvelope);
String ss=httpTransport.responseDump; 
Log.d("Result --- ", ss);

This will print the complete xml file which has been returned by the web service. 这将打印Web服务返回的完整xml文件。

Try it this WAy . 试试这个WAy。

try {

    httpTransport.call(SOAP_ACTION, soapEnvelope);
    SoapObject result = (SoapObject) soapEnvelope.getResponse();


String element = ((SoapObject)result.getPropertySafely("schema")).getPropertySafely("element").toString(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM