如何通过在肥皂请求对象(how to pass object in soap request)

2019-10-18 10:19发布

在我的应用程序之一,我想送的Object ,以WCF服务。 这个Object绑定三个数据。 我不知道如何发送邮件。

我努力了

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());

这条路。 在这里,我要绑定RoleIDRoleNameActionBy作为一个对象。 在WCF服务我的同事转换这个对象作为自己的舒适的对象,然后提取它。 所以我想绑定。 是否有可能啦。 如果可能的手段请指导我。

提前致谢。

Answer 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;


Answer 2:

你应该创建一个实现kvmserializable接口的类

这是通过ksoap2发送复杂的对象教程



文章来源: how to pass object in soap request