从ANDROID向soap web服务发出的Xml字符串请求
我正在从android应用程序调用ksoap web服务,但它引发异常: 请看下面是我的代码:从ANDROID向soap web服务发出的Xml字符串请求,android,android-ksoap2,Android,Android Ksoap2,我正在从android应用程序调用ksoap web服务,但它引发异常: 请看下面是我的代码: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (android.os.Build.VERSION.SDK_INT
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
try {
makingEnvelopAndReady(URL, METHOD_NAME, 10, 10,
"Daily", 5000, 10, "Hourly");
} catch (Exception e) {
// TODO: handle exception
Log.v("Excepotuion in main method : ",
"Excepotuion in main method : " + e);
}
}
makingelevelopmanderady()方法
它有以下错误:
09-11 19:48:39.672: I/System.out(2459): executing requestPOST http://brainteclabs.com:8180/MobileContractorCalculationService.svc HTTP/1.1
09-11 19:48:39.672: I/SOAP Request(2459): <?xml version=\"1.1\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><Calculate xmlns=\"http://tempuri.org/\"><inputRate>10</inputRate><rateFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>10</a:RateFrequencyId><a:RateFrequencyName>Daily</a:RateFrequencyName></rateFrequency><nonTaxableExpense>5000</nonTaxableExpense><expenseFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>10</a:RateFrequencyId><a:RateFrequencyName>Hourly</a:RateFrequencyName></expenseFrequency></Calculate></s:Body></soap:Envelope>
09-11 19:48:49.853: I/Reponse Header(2459): Begin...
09-11 19:48:49.853: I/Reponse Header(2459): StatusLine:HTTP/1.1 400 Bad Request
09-11 19:48:49.863: I/Reponse Header(2459): Cache-Control: private
09-11 19:48:49.863: I/Reponse Header(2459): Server: Microsoft-IIS/8.0
09-11 19:48:49.863: I/Reponse Header(2459): Set-Cookie: ASP.NET_SessionId=ebjsi0xuqhbprtzo1dozjkws; path=/; HttpOnly
09-11 19:48:49.863: I/Reponse Header(2459): X-AspNet-Version: 4.0.30319
09-11 19:48:49.863: I/Reponse Header(2459): X-Powered-By: ASP.NET
09-11 19:48:49.863: I/Reponse Header(2459): Date: Wed, 11 Sep 2013 14:19:07 GMT
09-11 19:48:49.873: I/Reponse Header(2459): Content-Length: 0
09-11 19:48:49.887: I/Reponse Header(2459): END...
我已经努力了这么多,用了这么多的方法请求ksoap web服务,但仍然没有得到任何成功的结果,请查看我的代码并告诉我我遗漏了什么。从信封中删除额外的字符,如“/”。现在应该是如下所示
String SOAPRequestXMLBody = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><Calculate xmlns=\"http://tempuri.org/\"><inputRate>"
+ "10"
+ "</inputRate><rateFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>"
+ "10"
+ "</a:RateFrequencyId><a:RateFrequencyName>"
+ "Hourly"
+ "</a:RateFrequencyName></rateFrequency><nonTaxableExpense>"
+ "5000"
+ "</nonTaxableExpense><expenseFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>"
+ "10"
+ "</a:RateFrequencyId><a:RateFrequencyName>"
+ "Hourly"
+ "</a:RateFrequencyName></expenseFrequency></Calculate></s:Body></s:Envelope>";`enter code here`
String SOAPRequestXMLBody=“”
+ "10"
+ ""
+ "10"
+ ""
+“每小时”
+ ""
+ "5000"
+ ""
+ "10"
+ ""
+“每小时”
+ "";`在这里输入代码`
现在它可以正常工作了
09-11 19:48:39.672: I/System.out(2459): executing requestPOST http://brainteclabs.com:8180/MobileContractorCalculationService.svc HTTP/1.1
09-11 19:48:39.672: I/SOAP Request(2459): <?xml version=\"1.1\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><Calculate xmlns=\"http://tempuri.org/\"><inputRate>10</inputRate><rateFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>10</a:RateFrequencyId><a:RateFrequencyName>Daily</a:RateFrequencyName></rateFrequency><nonTaxableExpense>5000</nonTaxableExpense><expenseFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>10</a:RateFrequencyId><a:RateFrequencyName>Hourly</a:RateFrequencyName></expenseFrequency></Calculate></s:Body></soap:Envelope>
09-11 19:48:49.853: I/Reponse Header(2459): Begin...
09-11 19:48:49.853: I/Reponse Header(2459): StatusLine:HTTP/1.1 400 Bad Request
09-11 19:48:49.863: I/Reponse Header(2459): Cache-Control: private
09-11 19:48:49.863: I/Reponse Header(2459): Server: Microsoft-IIS/8.0
09-11 19:48:49.863: I/Reponse Header(2459): Set-Cookie: ASP.NET_SessionId=ebjsi0xuqhbprtzo1dozjkws; path=/; HttpOnly
09-11 19:48:49.863: I/Reponse Header(2459): X-AspNet-Version: 4.0.30319
09-11 19:48:49.863: I/Reponse Header(2459): X-Powered-By: ASP.NET
09-11 19:48:49.863: I/Reponse Header(2459): Date: Wed, 11 Sep 2013 14:19:07 GMT
09-11 19:48:49.873: I/Reponse Header(2459): Content-Length: 0
09-11 19:48:49.887: I/Reponse Header(2459): END...
private final String URL = "http://brainteclabs.com:8180/MobileContractorCalculationService.svc";
private final String SOAP_ACTION = "http://tempuri.org/IMobileContractorCalculationService/Calculate";
private final String METHOD_NAME = "Calculate";
String SOAPRequestXMLBody = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><Calculate xmlns=\"http://tempuri.org/\"><inputRate>"
+ "10"
+ "</inputRate><rateFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>"
+ "10"
+ "</a:RateFrequencyId><a:RateFrequencyName>"
+ "Hourly"
+ "</a:RateFrequencyName></rateFrequency><nonTaxableExpense>"
+ "5000"
+ "</nonTaxableExpense><expenseFrequency xmlns:a=\"http://schemas.datacontract.org/2004/07/FusionPeople.MobileContractor.DomainModel\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><a:RateFrequencyId>"
+ "10"
+ "</a:RateFrequencyId><a:RateFrequencyName>"
+ "Hourly"
+ "</a:RateFrequencyName></expenseFrequency></Calculate></s:Body></s:Envelope>";`enter code here`