The example compares the simple record the thought
1. Define entity and method declarations in interfaces
Login information
[OperationContract]
[WebInvoke (UriTemplate = "Loginf/{name}/{pwd}", Method = "POST", Responseformat = Webmessageformat.json)]
Loginf Getloginf (string name, string pwd);
2//Data Exchange entity class
[DataContract]
public class Loginf
{
[DataMember]
public string UserId {get; set;}
[DataMember]
public bool LogTag {get; set;}
[DataMember]
public string ErrMsg {get; set;}
}
3 Service implementations
Simple test
Public Loginf Getloginf (string name, string pwd)
{
Loginf Loginf = new Loginf ();
if (name = = "111" && pwd = = "111")
{
Loginf. UserId = "100";
Loginf. LogTag = true;
loginf.errmsg = " Success ";
}
Else
{
Loginf. UserId = "0";
Loginf. LogTag = false;
Loginf.errmsg = "Verification Failed";
}
return loginf;
}
4 Change the binding mode to WebHttpBinding in Web. config
Binding= "WebHttpBinding"
5 Calls
Nsurl *url = [Nsurl urlwithstring:@http://192.268.0.11:9422/Service1.svc/LogInf/111/111];
ASIHTTPRequest *request = [ASIHTTPRequest Requestwithurl:url];
[Request setrequestmethod:@"POST"];
[Request startsynchronous];
Nserror *error = [request ERROR];
if (!error) {
NSString *response = [request responsestring];
Uialertview *alertview = [[Uialertview alloc] initwithtitle:@"test"
Message:response
Delegate:nil
cancelbuttontitle:@"OK"
Otherbuttontitles:nil];
[Alertview show];
[Alertview release];
}
6 return
{"LogTag": True, "UserId": "+", "ErrMsg": "Success"}