通过错误吸收Web服务(SoapFault - faultcode:' a:InternalServiceFault')

时间:2017-02-21 11:21:36

标签: c# android ios asp.net-mvc-3 xamarin

请帮我解决错误。

public static HashMap<String, Object> callSOAPServer(StringBuffer soap /* YOUR XML GOES HERE*/,String action) {
    int count,size;
    int total=0;

    HashMap<String, Object> xMap = new HashMap<String, Object>();
    byte[] result = null;
    byte[] data = new byte[1024*1024];
    HttpClient httpclient = new DefaultHttpClient(); /* Your probably need to edit client for your needs, like timeout, scheme, etc */
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    DataInputStream is = null;
    boolean download = true;
   // HttpPost httppost = new HttpPost(/* YOUR URL GOES HERE */ );
    HttpPost httppost = new HttpPost("http://192.168.0.120:86/UserService.svc/basic");
    //httppost.setHeader("soapaction", action);
    httppost.setHeader("Content-Type", "text/xml; charset=utf-8");
    try {
        HttpEntity entity = new StringEntity(soap.toString(), HTTP.UTF_8);
        httppost.setEntity(entity);
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity r_entity = response.getEntity();
        if (r_entity != null) {
            result = new byte[(int) r_entity.getContentLength()];
            size = result.length;
            if (r_entity.isStreaming()) {
                is = new DataInputStream(r_entity.getContent());
                while((count = is.read(data, 0, data.length)) != -1) {
                    buffer.write(data, 0, count);
                    total +=count;
                }
            }
            buffer.flush();
            result = buffer.toByteArray();
            data = null;
            buffer = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        result = null;
    }
    if(result !=null){
        try {
            String sb;
            String sn;
            sb = new String(result, "UTF-8");
            sn = sb.replace("&amp;", "AMP"); //Precaution for SAX parser
            result = sn.getBytes();
            Log.d("",result.toString());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        xMap.put("STATUS", "OK");
        xMap.put("SOAP", result);
    }else{
        if(xMap.get("STATUS") == null) {
            xMap.put("STATUS", "ERROR");
        }
    }
    httpclient.getConnectionManager().shutdown();
    return xMap;
    // List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    //nameValuePairs.add(new BasicNameValuePair("Username", "Hari"));
    //nameValuePairs.add(new BasicNameValuePair("Password", "Hh123456"));
    // nameValuePairs.add(new BasicNameValuePair("soap.toString()", HTTP.UTF_8));
    //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
}
  

通过错误吸收Web服务(SoapFault - faultcode:   &#39;一个:InternalServiceFault&#39)

0 个答案:

没有答案