Simply record the use of entity objects as parameters for delivery!
There is no problem when using WebService on the server, but there is no problem with the arguments passed when replacing WCF!
Service-Side code:
Service1.svc
namespace wcfteacherservice{ //Note: Using the rename command on the Refactor menu, you can change the class name "Service1" in Code, SVC, and configuration files at the same time. //Note: In order to start the WCF test client to test this service, select Service1.svc or Service1.svc.cs in Solution Explorer and start debugging. Public class Service1:iservice1 {Public string DoWork (Testmodel model) { log4net. Logmanager.getlogger (this. GetType ()). Error (model. AA); return model. AA;}}}
TestModel.cs
Using system;using system.collections.generic;using system.linq;using system.web;using System.ServiceModel;using System.runtime.serialization;namespace wcfteacherservice{public class Testmodel {public string AA {get ; Set } }}
The Android client uses http://www.wsdl2code.com/pages/Home.aspx to generate the required code;
@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); Service1 service = new Service1 (); Testmodel model = new Testmodel (); MODEL.AA = "123"; Service.eventhandler = new Iwsdl2codeevents () {@Overridepublic void Wsd L2codefinished (String methodName, Object Data) {@SuppressWarnings ("unused") String AA = MethodName;} @Overridepublic void Wsdl2codestartedrequest () {} @Overridepublic void Wsdl2codefinishedwithexception (Exception ex) {} @Overridepublic void Wsdl2codeendedrequest () {}};try {service. Doworkasync (model);} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();}}
There is no problem with the value type as a parameter in WCF, such as: Int,string,bool, but the custom entity object as a parameter always gets the value! Later after Fiddler grabbed the packet repeatedly contrast, originally is the Testmodel namespace and the DoWork method namespace inconsistency caused!
So modify the above TestModel.cs; Add a namespace declaration above the class name
Using system;using system.collections.generic;using system.linq;using system.web;using System.ServiceModel;using System.runtime.serialization;namespace wcfteacherservice{ [DataContract (namespace= "http://tempuri.org/")] Public class Testmodel { [DataMember] public string AA {get; set;}}}
You can also add the same namespace to the interface.
namespace wcfteacherservice{ //Note: Using the rename command on the Refactor menu, you can change the interface name "IService1" in code and configuration files at the same time. [ServiceContract (namespace= "http://tempuri.org/"] public interface IService1 { [ OperationContract] string DoWork (Testmodel model);} }
As long as you modify the server-side namespace, iOS and Android automatically generate code without changes!
The record is very simple, so simple question but debugging a day more Ah!
Android/ios access to WCF pass parameters as entity object issues