android - 传递soap对象(soap1.2)android时无法从HttpResponse获取响应?

标签 android soap httpresponse soap1.2

代码:

            String response ;
            try {
                final String SOAP_ACTION = "http://tempuri.org/myAction";
                final String URL = "MYURL";
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(URL);
                String bodyOut = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">"
                        + "   <soapenv:Header/>"
                        + "   <soapenv:Body>"
                        ........ MY Data.......
                        + "      </tem:Login>"
                        + "   </soapenv:Body>" + "</soapenv:Envelope>";

                StringEntity se = new StringEntity(bodyOut, HTTP.UTF_8);
                    //StringEntity se = new StringEntity(request1, HTTP.UTF_8); 
                se.setContentType("text/xml");
                httpPost.addHeader("SOAPAction", SOAP_ACTION);
                httpPost.setEntity(se);

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity resEntity = httpResponse.getEntity();
                response = EntityUtils.toString(resEntity);
                if (response != null) {
                    Log.i("Response", "" + response);// this is not being printed
                    Log.i("test response", "not null");// this is being printed
                }
                else
                    Log.i("Response", "null");
            } catch (Exception e) {
                e.printStackTrace();
            }

没有异常(exception),但是:Log.i("Response", ""+ response);//这没有被打印

LogCat:

08-02 19:04:51.929: I/test response(20413): not null

最佳答案

作为其wsHttpBinding WCF服务Android

所以我使用以下方法解决了这个问题:

String METHOD_NAME = "MyMethodName"; 
String NAMESPACE = "http://tempuri.org/"; 
String URL = "MyUr;";
String SOAP_ACTION = "http://tempuri.org/MySoapAction"; 



SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

PropertyInfo req = new PropertyInfo();
req.name = "xmlstring";
req.namespace = NAMESPACE;
req.type = String.class;
req.setValue("........ MY Data.......");// without these `tags <soapenv:`
request.addProperty(req);

Element e = new Element();
e.setName("To");
e.setNamespace("http://www.w3.org/2005/08/addressing");
e.addChild(Node.TEXT,"MyUrl");

Element e1 = new Element();
e1.setName("Action");
e1.setNamespace("http://www.w3.org/2005/08/addressing");
e1.addChild(Node.TEXT,
        "http://tempuri.org/SoapAction");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.headerOut = new Element[] { e, e1 };
envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();

String resultData = result.toString();
Log.i("Result", "" + resultData);

关于android - 传递soap对象(soap1.2)android时无法从HttpResponse获取响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18018232/

相关文章:

android - Kivy Buildozer 无法构建 apk,命令失败 : ./distribute.sh -m "kivy"d

java - 在 Android 上读/写外部存储

c# - 如何在 ASP.NET 中调用 SOAP 服务

javascript - 是否可以使用 jQuery xml 处理程序解析 SOAP 响应?

JSON 编码返回空白 Golang

android - 如何处理 onItemClick 中的单独 View 点击?

Android Parse——具有字段/列列表相等条件的ParseQuery

c# - HTTP 请求未经客户端身份验证方案 'Ntlm' 授权。从服务器收到的身份验证 header 是 'Negotiate,NTLM'

c# - 如何返回带有错误消息或异常的 NotFound() IHttpActionResult?

swift - 如何在 swift 中围绕 Alamofire.authenticate 方法制作登录异步函数包装器?