我需要从我的应用程序发送和接收JSON字符串到SOAP Web服务(.svc)

时间:2016-06-02 07:18:11

标签: android

我需要从我的应用程序向SOAP Web服务(.svc)发送和接收JSON字符串。我不知道Web服务的属性,它有多个肥皂动作。我所知道的是一个json字符串格式,我必须发送。然后我必须验证JSON字符串并相应地获取JSON字符串。一切都需要使用POST来完成。

我尝试了以下代码:

protected Void doInBackground(String... params) {
    try {
        HttpPost request = new HttpPost("http://myurl.svc");

        Log.d("after Conection:","here");

        JSONStringer json = new JSONStringer().my json data.endObject();

        Log.d("after String:","here");

        StringEntity entity = new StringEntity(json.toString(), "UTF-8");
        entity.setContentType("application/json;charset=UTF-8");//text/plain;charset=UTF-8
        entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));
        request.setEntity(entity);

        // Send request to WCF service
        DefaultHttpClient httpClient = new DefaultHttpClient();

        HttpResponse response = httpClient.execute(request);

        Log.d("WebInvoke", "Saving : " + response.getStatusLine().getStatusCode());
        String str="";

        str=EntityUtils.toString(response.getEntity(),"UTF-8");

        Log.d("pangti:", str);
        JSONObject jobj=null;
        String data = EntityUtils.toString(entity,"utf-8");

        Log.d("String1:",data);
        jobj=new JSONObject(data);
        String notes = jobj.getString("Dep");
        JSONArray jarray=jobj.getJSONArray("Fare");
        Log.d("String:|NOtes",notes);

        //JSONArray object=new JSONArray(str);

        if(entity.getContentLength()!=0){
            //Reader flightReader = new InputStreamReader(response.getEntity().getContent());
            //InputStream instream = entity.getContent();
            //JSONObject object=new JSONObject("wsdl:definitions");
            Log.d("String:|Non-Zero","Non zero");
        }
    }
    catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(),"Error"+e,Toast.LENGTH_SHORT).show();
    }

    return null;
}

0 个答案:

没有答案