Android Connect WCF rest Note point

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.