【发布时间】:2014-03-10 16:12:58
【问题描述】:
我正在尝试向我的 Web 服务发送一个复杂的对象并返回一个字符串值,但我的 android 的 logcat 返回 Null 引用
ksoap2发送对象的完整代码
Questionnairekeyval qk = new Questionnairekeyval(5, 8, "Questionnaire1", "", "", "", "", "", "", "", "");
PropertyInfo pi = new PropertyInfo();
pi.setName("Questionnairekeyval");
pi.setValue(qk);
pi.setType(qk.getClass());
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
// 2. Set the request parameters
envelope.setOutputSoapObject(request);
envelope.addMapping(WS_NAMESPACE, "Questionnairekeyval",
new Questionnairekeyval().getClass());
// 3. Create a HTTP Transport object to send the web service request
HttpTransportSE httpTransport = new HttpTransportSE(WSDL_URL);
// httpTransport.debug = true; // allows capture of raw request/respose
// in
// Logcat
// 4. Make the web service invocation
httpTransport.call(SOAP_ACTION, envelope);
String result;
if (envelope.bodyIn instanceof SoapFault) { // SoapFault =
// FAILURE
SoapFault soapFault = (SoapFault) envelope.bodyIn;
throw new Exception(soapFault.getMessage());
} else {
// SoapObject = SUCCESS
SoapPrimitive soapObject = (SoapPrimitive) envelope.getResponse();
result = (soapObject).toString();
Log.wtf("result SOAPObject", result + " " + soapObject);
}
C#获取对象并返回一个字符串
[WebMethod]
public String putAnswers(Questionnairekeyval reponse)
{
int a = reponse.idClient;
return Convert.ToString(a);
}
【问题讨论】: