问题
In one of my app I want to send an Object
to WCF service. This Object
binds three data. I don't know how to send it.
I have tried
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapObject map = new SoapObject(NAMESPACE, "New Role");
map.addProperty("RoleID", "ROLEAAAA0001");
map.addProperty("RoleName", "MOB_Gunaseelan");
map.addProperty("ActionBy", "Gunaseelan");
request.addSoapObject(map);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(URL);
try {
transport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
}
SoapFault fault = (SoapFault) envelope.bodyIn;
System.out.println("Fault : " + fault.toString());
This way. Here I want to bind RoleID
,RoleName
,ActionBy
as one Object. In WCF service my colleague convert this object as his comfortable object and then extracts it. So I want to bind. Is it possible friends. If possible means please guide me.
Thanks in advance.
回答1:
int ArryIndex = 0;
SoapObject soReturn ;
String [] ParameterName = new String[3];
String [] ParameterValue = new String[3];
ParameterName[0] = "RoleID";
ParameterValue[0] = ROLEAAAA0001;
ParameterName[1] = "RoleName";
ParameterValue[1] = MOB_Gunaseelan;
ParameterName[2] = "ActionBy";
ParameterValue[2] = Gunaseelan;
objWSConfig.SetURL(URL, WebService);
objWSConfig.SetSOAPAction(SoapAction, MethodName);
objWSConfig.SetWebService(WebService);
objWSConfig.SetMethod(MethodName);
ws_Method = objWSConfig.getMethod();
ws_Namespace = objWSConfig.getNamespace();
ws_URL = objWSConfig.getURL();
ws_SOAPAction = objWSConfig.getSOAPAction();
SoapObject request = new SoapObject(ws_Namespace,ws_Method);
for(ArryIndex = 0 ; ArryIndex < ParameterName.length ; ArryIndex ++)
{
PropertyInfo ParaObj = new PropertyInfo();
ParaObj.type = PropertyInfo.OBJECT_CLASS;
ParaObj.namespace = ws_Namespace;
ParaObj.setName(ParameterName[ArryIndex].toString());
ParaObj.setValue(ParameterValue[ArryIndex].toString());
request.addProperty(ParaObj);
}
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
//envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setAddAdornments(true);
HttpTransportSE androidHttpTransport = new HttpTransportSE(ws_URL);
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
androidHttpTransport.call(ws_SOAPAction, envelope);
androidHttpTransport.debug = true;
resultsRequestSOAP = (SoapObject) envelope.bodyIn;
回答2:
you should create a class which implements kvmserializable interface
This is a tutorial for sending complex objects through ksoap2
来源:https://stackoverflow.com/questions/17991857/how-to-pass-object-in-soap-request