Ksoap2添加属性(Android)
对于那些经常使用ksoap2库的人来说,我的问题应该很简单。我在web服务中的一个web方法有两个属性,所以我可以知道如何使用eclipse中的addproperty将两个数据传递给web服务。Plz提供了一个示例短代码Ksoap2添加属性(Android),android,ksoap2,Android,Ksoap2,对于那些经常使用ksoap2库的人来说,我的问题应该很简单。我在web服务中的一个web方法有两个属性,所以我可以知道如何使用eclipse中的addproperty将两个数据传递给web服务。Plz提供了一个示例短代码 public static String Login(Context c, String username, String password, String fleetId) throws IOException, XmlPullParserExcept
public static String Login(Context c, String username, String password,
String fleetId) throws IOException, XmlPullParserException {
String METHOD_NAME = "Login";
String SOAP_ACTION = "http://tempuri.org/xxxxxx/";
SOAP_ACTION = SOAP_ACTION + METHOD_NAME;
SoapObject request = new SoapObject(CommonVariable.NAMESPACE,
METHOD_NAME);
// Use this to add parameters
request.addProperty("username", username);
request.addProperty("password", password);
Log.i("request", "request:" + request);
// Declare the version of the SOAP request
Log.i(WebCalls, "URL " + CommonVariable.URL);
Log.i(WebCalls, "Method Name " + METHOD_NAME);
Log.i(WebCalls, "request Name " + request);
String SoapResult = null;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(
CommonVariable.URL);
// this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
if (envelope.bodyIn instanceof SoapFault) {
SoapResult = ((SoapFault) envelope.bodyIn).faultstring;
} else {
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
SoapResult = resultsRequestSOAP.getProperty(0).toString();
}
Log.i(WebCalls, "Response " + SoapResult);
return SoapResult;
}
您希望在webservice中添加如下属性:
SoapObject request = new SoapObject(CommonVariable.NAMESPACE,
METHOD_NAME);
// Use this to add parameters
request.addProperty("username", username);
request.addProperty("password", password);
我希望它对你有用。你说的两个数据是什么意思?用谷歌搜索一下。。你会发现很多示例Spublic void ProductImageInsertion(字符串名称,字节imageLink)//类似于上面的示例……我需要向void函数输入两个数据。你应该写一些关于代码的内容,答案中的简单代码不是有效的答案。例如:public void ProductImageInsertion(字符串名称,字节imageLink)//我需要向这个void函数输入两个数据,但我只知道如何向一个函数添加属性,当我尝试两个时,我的logcat会出错