android - Pass Object to WCF service -
i totally new wcf service. don't know how pass complex type wcf service.
public class mainactivity extends activity implements onclicklistener { soapobject result; button b; private static string namespace = "http://tempuri.org/"; private static string method_name = "insertdata"; private static string soap_action = "http://tempuri.org/iwcfmastertable/insertdata"; private static string url = "http://172.16.0.1:55355/wcfmastertable.svc"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); b = (button) findviewbyid(r.id.button1); b.setonclicklistener(this); } @override public void onclick(view v) { if (v.getid() == r.id.button1) { myclass mc = new myclass(mainactivity.this); mc.execute(""); } } class myclass extends asynctask<string, void, soapobject> { jsonobject jobj; mainactivity activity; public myclass(mainactivity activity) { this.activity = activity; } @override protected soapobject doinbackground(string... params) { try { clsmastertable ct = new clsmastertable(); soapobject request = new soapobject(namespace, method_name); ct = ct.getdata(); system.out.println(ct.tableid); request.addproperty("args", ct); soapserializationenvelope envelope = new soapserializationenvelope( soapenvelope.ver12); envelope.setoutputsoapobject(request); envelope.dotnet = true; 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()); result = (soapobject) envelope.bodyin; system.out.println("result : " + result); } catch (exception e) { system.out.println("exception : " + e.tostring()); } return result; } @override protected void onpostexecute(soapobject result) { super.onpostexecute(result); } } }
and
public class clsmastercasetype { string id, name, mark; public clsmastercasetype getdata() { mark= "88"; id = "ctypaaaa0005"; name= "karthik"; return this; } }
this way have tried pass complex type. throws following exception
08-08 12:53:42.376: w/system.err(7845): java.lang.runtimeexception: cannot serialize: com.elintsys.wcfservice.clsmastercasetype@40fcbdf0 08-08 12:53:42.376: w/system.err(7845): @ org.ksoap2.serialization.soapserializationenvelope.writeelement(soapserializationenvelope.java:687) 08-08 12:53:42.376: w/system.err(7845): @ org.ksoap2.serialization.soapserializationenvelope.writeproperty(soapserializationenvelope.java:671) 08-08 12:53:42.386: w/system.err(7845): @ org.ksoap2.serialization.soapserializationenvelope.writeobjectbody(soapserializationenvelope.java:640) 08-08 12:53:42.386: w/system.err(7845): @ org.ksoap2.serialization.soapserializationenvelope.writeobjectbody(soapserializationenvelope.java:624) 08-08 12:53:42.386: w/system.err(7845): @ org.ksoap2.serialization.soapserializationenvelope.writeelement(soapserializationenvelope.java:681) 08-08 12:53:42.386: w/system.err(7845): @ org.ksoap2.serialization.soapserializationenvelope.writebody(soapserializationenvelope.java:597) 08-08 12:53:42.386: w/system.err(7845): @ org.ksoap2.transport.transport.createrequestdata(transport.java:101)
how pass object in soap request have tried way too. please me friends. wasted 3 days this. in advance.
i have made changes in code.
1)
soapserializationenvelope envelope = new soapserializationenvelope( soapenvelope.ver12);
change
soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11);
2)
soapobject response = (soapobject) envelope.bodyin;
change into
soapprimitive response = (soapprimitive)envelope.getresponse();
Comments
Post a Comment