如何处理SOAPPRIMITIVE响应 [英] How to process the SOAPPRIMITIVE response

查看:221
本文介绍了如何处理SOAPPRIMITIVE响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有WCF方法返回字符串类型。

I have WCF method that return String type.

这是我的输出

{表1:[{表名:
  LoadDistributor,说明:
  分销商,MandatoryFlag:
  1,状态:,优先级:
  0},{表名:
  LoadPrice,说明:价格
  ,MandatoryFlag:1,状态:
  ,优先级:0},{表名:
  LoadProduct,说明:产品
  ,MandatoryFlag:1,状态:
  ,优先级:0},{表名:
  LoadTradeSchemeDetail,说明
  :TradeSchemeDeta,MandatoryFlag:
  1,状态:,优先级:
  0},{表名:
  RD.AlternativeProductDetail,说明
  :AltProdutDetail,MandatoryFlag:
  0,状态:,优先级:
  0},{表名:
  RD.AlternativeProductHeader,说明
  :AltProdutHeader,MandatoryFlag:
  0,状态:,优先级:
  0},{表名:
  RD.BatchPriceDetail,说明:
  BatchPrice,MandatoryFlag:
  1,状态:,优先级:
  0},{表名:
  RD.Executive,说明:
  行政,MandatoryFlag:
  1,状态:,优先级:
  0},{表名:
  RD.Route,说明:路线
  ,MandatoryFlag:1,状态:
  ,优先级:0},{表名:
  RD.vwRetailer,说明:
  零售商,MandatoryFlag:
  1,状态:,优先级:
  0},{表名:
  RD.vwRouteDetail,说明:
  RouteDetail,MandatoryFlag:
  1,状态:,优先级:
  0},{表名:
  XA.vwProductType,说明:
  品牌产品C,MandatoryFlag:
  1,状态:,优先级:
  0},{表名:
  XA.vwTown,说明:城
  ,MandatoryFlag:1,状态:
  ,优先:0}]}

{"Table1" : [{"TableName" : "LoadDistributor","Description" : "Distributor ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "LoadPrice","Description" : "Price ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "LoadProduct","Description" : "Product ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "LoadTradeSchemeDetail","Description" : "TradeSchemeDeta","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.AlternativeProductDetail","Description" : "AltProdutDetail","MandatoryFlag" : "0","Status" : "","Priority" : "0"},{"TableName" : "RD.AlternativeProductHeader","Description" : "AltProdutHeader","MandatoryFlag" : "0","Status" : "","Priority" : "0"},{"TableName" : "RD.BatchPriceDetail","Description" : "BatchPrice ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.Executive","Description" : "Executive ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.Route","Description" : "Route ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.vwRetailer","Description" : "Retailer ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.vwRouteDetail","Description" : "RouteDetail ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "XA.vwProductType","Description" : "Brand Product C","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "XA.vwTown","Description" : "Town ","MandatoryFlag" : "1","Status" : "","Priority" : "0"}]}

这是我的SOAP处理方法

This is my Soap processing method

    // ksoap2 calling wcf
public SoapPrimitive soapPrimitive(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException {
    SoapPrimitive responses = null;
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
    request.addProperty("strExec", "7067");
    request.addProperty("strBusinessUnit", "HEMA");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);  
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);  
    httpTransport.debug = true; 

    try{

        Log.w("Log_cat" ,"*********" + envelope.toString());
        httpTransport.call(SOAP_ACTION, envelope);
        Log.w("log_tag", " ===========" +SOAP_ACTION );

        // Object result = (Object)envelope.getResponse();
        // JSONArray jArray = new JSONArray(result.toString());
        // Log.w("log_tag", " ===*********==" +jArray );

         responses = (SoapPrimitive)envelope.getResponse();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

   // Object response= envelope.getResponse();
    return responses;
 }

我的C#方法返回的字符串使用JSON(作为一个字符串)。

My C# method return String with JSON( as a String).

如何只在列表或数组中获得的表名。
请帮我。什么是错在这里?

How to get the Table name only in the List or Array. Please help me .What is wrong here?

推荐答案

你了解SOAP和JSON的区别? KSOAP是加工服务期待SOAP请求并返回SOAP响应。所以,除非你有SOAP服务使用JSON返回一个字符串元素你不需要(且不能使用)KSOAP。如果你有REST服务返回的JSON使用简单的 DefaultHttpClient HttpPost 为<一个href=\"http://stackoverflow.com/questions/5167341/how-to-pass-json-array-as-parameter-to-a-webservice-using-ksoap2-in-android\">described这里例子。如果您正在使用JSON所有的时间也回答您的$p$pvious问题

Do you understand the difference between SOAP and JSON? kSOAP is for processing services expecting SOAP request and returning SOAP response. So unless you have SOAP service returning single string element with JSON you don't need (and cannot use) kSoap. If you have REST service returning JSON use simple DefaultHttpClient and HttpPost as described for example here. If you are using JSON all the time it also answers your previous question.

这篇关于如何处理SOAPPRIMITIVE响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆