code:
字符串响应;
尝试 {
最后弦乐SOAP_ACTION =http://tempuri.org/myAction;
最终的字符串URL =MYURL;
HttpClient的HttpClient的=新DefaultHttpClient();
HttpPost httpPost =新HttpPost(URL);
字符串bodyOut =< soapenv:信封的xmlns:soapenv = \HTTP://schemas.xmlsoap.org/soap/envelope/ \的xmlns:TEM = \HTTP://tempuri.org/ \>中
+< soapenv:页眉/>中
+< soapenv:身体与GT;
........我的数据.......
+< / TEM:登录>中
+< / soapenv:身体与GT; +< / soapenv:信封>中;
StringEntity SE =新StringEntity(bodyOut,HTTP.UTF_8);
// StringEntity SE =新StringEntity(request1,HTTP.UTF_8);
se.setContentType(为text / xml);
httpPost.addHeader(SOAPAction报,SOAP_ACTION);
httpPost.setEntity(SE);
HTT presponse HTT presponse = httpClient.execute(httpPost);
HttpEntity resEntity = HTT presponse.getEntity();
响应= EntityUtils.toString(resEntity);
如果(响应!= NULL){
Log.i(响应,+响应); //这不是正印
Log.i(测试响应,不为空); //这是被印
}
其他
Log.i(响应,空);
}赶上(例外五){
e.printStackTrace();
}
也不例外,但是: Log.i(响应,+响应); //这不是正印
LogCat中:
08-02 19:04:51.929:I /测试响应(20413):不为null
解决方案
为的wsHttpBinding
WCF服务的Android
所以,我已经解决了这个使用以下内容:
字符串METHOD_NAME =MyMethodName;
字符串NAMESPACE =http://tempuri.org/;
字符串的URL =MyUr;;
字符串SOAP_ACTION =http://tempuri.org/MySoapAction;
SoapObject请求=新SoapObject(命名空间METHOD_NAME);
的PropertyInfo REQ =新的PropertyInfo();
req.name =的xmlString;
req.namespace = NAMESPACE;
req.type =为String.class;
req.setValue(........我的数据......); //没有这些'标签< soapenv:`
request.addProperty(REQ);
元素e =新元素();
e.setName(到);
e.setNamespace(http://www.w3.org/2005/08/addressing);
e.addChild(Node.TEXTMyUrl);
元素E1 =新元素();
e1.setName(行动);
e1.setNamespace(http://www.w3.org/2005/08/addressing);
e1.addChild(Node.TEXT,
http://tempuri.org/SoapAction);
SoapSerializationEnvelope包=新SoapSerializationEnvelope(
SoapEnvelope.VER12);
envelope.dotNet = TRUE;
envelope.headerOut =新的元素[] {E,E1};
envelope.setOutputSoapObject(要求);
HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,包);
SoapPrimitive结果=(SoapPrimitive)envelope.getResponse();
串resultData = result.toString();
Log.i(结果,+ resultData);
Code :
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();
}
no exception but: Log.i("Response", "" + response);// this is not being printed
LogCat:
08-02 19:04:51.929: I/test response(20413): not null
解决方案
as its wsHttpBinding
WCF service Android
So I Have Solved this using Following :
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);