Calling WCF in iOS

Source: Internet
Author: User

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"}

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.