The 1.datacontract element has a default value, the null value is serialized as JSON when there is a problem, the exception does not jump in debugging, but TCP tracer does not response information, and then
Android Client reported system.eof error
[DataContract] public class UserData {private Long userId = (long) 0; private string username = string. Empty; private string nickname = String. Empty; private string sex = String. Empty; private string icon = string. Empty; private string mobilephone = String. Empty; Private DateTime registerdate = DateTime.Now; private string customid = String. Empty; private string flag = String. Empty; private string errorinfo = String. Empty; [DataMember] public long UserID {get {return UserId; } set {userId = value; }} [DataMember] public string UserName {get {return us Ername; } set {username = value; }} [DataMember] public string Nickname { get {return nickname; } set {nickname = value; }} [DataMember] public string Sex {get {return Sex; } set {sex = value; }} [DataMember] public string Icon {get {return Icon; } set {icon = value; }} [DataMember] public string Mobilephone {get {return Mobilephone; } set {mobilephone = value; }} [DataMember] public DateTime registerdate {get {ret Urn Registerdate; } set {registerdate = value; } } [DataMember] public string Customid {get {return customid; } set {customid = value; }} [DataMember] public string Flag {get {return Flag; } set {flag = value; }} [DataMember] public string ErrorInfo {get {return E Rrorinfo; } set {errorinfo = value; } } }View Code
2. Output WCF exceptions to the specified file
<?XML version= "1.0" encoding= "Utf-8"?><Configuration> <System.ServiceModel> <servicehostingenvironmentaspnetcompatibilityenabled= "true"/> <Behaviors> <servicebehaviors> <Behaviorname= "Webhttpservicebehavior"> <Servicemetadatahttpgetenabled= "true"Httpgeturl= "metadata"/> <ServicedebugIncludeexceptiondetailinfaults= "true"/> <DataContractSerializerMaxitemsinobjectgraph= "2147483647"/> </Behavior> </servicebehaviors> <endpointbehaviors> <Behaviorname= "Webhttpendpointbehavior"> <webhttphelpenabled= "true"/> </Behavior> </endpointbehaviors> </Behaviors> <Bindings> <webhttpbinding> <bindingcrossdomainscriptaccessenabled= "true"name= "WebHttpBinding"maxBufferSize= "2147483647"maxbufferpoolsize= "2147483647"MaxReceivedMessageSize= "2147483647"> <ReaderquotasmaxDepth= "2147483647"Maxstringcontentlength= "2147483647"Maxarraylength= "2147483647"Maxbytesperread= "2147483647"Maxnametablecharcount= "2147483647"/> </binding> </webhttpbinding> </Bindings> <Services> <Servicename= "ChatWithLocationServiceLib.services.LoginService"behaviorconfiguration= "Webhttpservicebehavior"> <EndpointAddress= "Http://192.168.0.175:3721/LoginService"binding= "WebHttpBinding"behaviorconfiguration= "Webhttpendpointbehavior"Contract= "ChatWithLocationServiceLib.interfaces.ILoginService"/> </Service> </Services> </System.ServiceModel> <system.webserver> <Modulesrunallmanagedmodulesforallrequests= "true"/> </system.webserver> <!--Save the specific error message in the Svclog file - <System.Diagnostics> <sources> <Sourcename= "System.ServiceModel"Switchvalue= "Warning"propagateactivity= "true"> <Listeners> <Addname= "xml" /> </Listeners> </Source> </sources> <sharedlisteners> <Addname= "xml"type= "System.Diagnostics.XmlWriterTraceListener"initializedata= "F:\wcf.svclog" /> </sharedlisteners> </System.Diagnostics></Configuration>
View Code
3. Declaring the Service interface
[ServiceContract] Public interface Iloginservice { [OperationContract (Name = "Login")] [WebInvoke (Method = "GET", Requestformat = Webmessageformat.json, responseformat = Webmessageformat.json, bodystyle = Webmessagebodystyle.bare, uritemplate = "Login/{gid}/{pwd}")] UserData Login (String GID, String PWD); [OperationContract (Name = "Registlogin")] [WebInvoke (Method = "POST", Requestformat = Webmessageformat.json, Responseformat = Webmessageformat.json, bodystyle = Webmessagebodystyle.bare, UriTemplate = "Registlogin")] UserData registlogin (UserData baseinfo); }
View Code
4. Implementing the Service Interface
[ServiceBehavior (InstanceContextMode = instancecontextmode.percall)] public class Loginservice:iloginservice {public UserData Login (String GID, String PWD) { Console.WriteLine ("GID" + gid + "; PWD: "+ pwd"; UserData data = new UserData (); Data. UserId =; Data. UserName = "Erer"; Data. ErrorInfo = "username fail"; return data; } Public UserData Registlogin (UserData baseinfo) { UserData data = new UserData (); Data. UserId = 0; Data. UserName = Baseinfo.username; return data; } }
View Code
Android Connect WCF rest Note point