下面我已经给出了在tomcat服务器上运行的服务器代码的详细信息,它正确地生成了wsdl文件。
在我的Android模拟器中,我安装了 KSOAP2 Lib文件来访问Web服务。
请帮我解决这个问题。 每当我在设备中添加两个数字时,它应该调用服务器代码。
我附有错误日志
服务器上的功能:
[
package com.testing;
public class Calculator {
public int addidtion(int a, int b ){
return a*b;
}
}
]
代码:
[
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int SDK_INT = android.os.Build.VERSION.SDK_INT;
if (SDK_INT > 8) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
String i = ((EditText)findViewById(R.id.editText)).getText().toString();
String J = ((EditText) findViewById(R.id.editText4)).getText().toString();
//Use this to add parameters
request.addProperty("addidtion", i);
request.addProperty("addidtion", J);
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = false;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION1, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) envelope.bodyIn;
if (result != null)
{
//Get the first property and change the label text
EditText text = (EditText) findViewById(R.id.editText4);
text.setText(result.getProperty(0).toString());
} else
{
//Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
]
WSDL:
[
<wsdl:definitions targetNamespace="http://testing.com"><!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
--><wsdl:types><schema elementFormDefault="qualified" targetNamespace="http://testing.com"><element name="addidtion"><complexType><sequence><element name="a" type="xsd:int"/><element name="b" type="xsd:int"/></sequence></complexType></element><element name="addidtionResponse"><complexType><sequence><element name="addidtionReturn" type="xsd:int"/></sequence></complexType></element></schema></wsdl:types><wsdl:message name="addidtionResponse"><wsdl:part element="impl:addidtionResponse" name="parameters">
</wsdl:part></wsdl:message><wsdl:message name="addidtionRequest"><wsdl:part element="impl:addidtion" name="parameters">
</wsdl:part></wsdl:message><wsdl:portType name="Calculator"><wsdl:operation name="addidtion"><wsdl:input message="impl:addidtionRequest" name="addidtionRequest">
</wsdl:input><wsdl:output message="impl:addidtionResponse" name="addidtionResponse">
</wsdl:output></wsdl:operation></wsdl:portType><wsdl:binding name="CalculatorSoapBinding" type="impl:Calculator"><wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="addidtion"><wsdlsoap:operation soapAction=""/><wsdl:input name="addidtionRequest"><wsdlsoap:body use="literal"/></wsdl:input><wsdl:output name="addidtionResponse"><wsdlsoap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="CalculatorService"><wsdl:port binding="impl:CalculatorSoapBinding" name="Calculator"><wsdlsoap:address location="http://localhost:8011/testws/services/Calculator"/></wsdl:port></wsdl:service></wsdl:definitions>
]
错误:
03-23 10:00:11.490 6275-6275/com.example.suvidhs.activity W/System.err: java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject
03-23 10:00:11.490 6275-6275/com.example.suvidhs.activity W/System.err: at com.example.suvidhs.activity.MainActivity$1.onClick(MainActivity.java:98)
03-23 10:00:11.490 6275-6275/com.example.suvidhs.activity W/System.err: at android.view.View.performClick(View.java:5198)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at android.view.View$PerformClick.run(View.java:21147)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at android.os.Looper.loop(Looper.java:148)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at java.lang.reflect.Method.invoke(Native Method)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-23 10:00:11.491 6275-6275/com.example.suvidhs.activity W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)