开发者

how to call WCF Service method in Iphone

I have made a WCF service(service1.svc) have 2 methods.

1.GetData()

2.ProductDetails(string ProdId)

Both returns a file in JSON format when i do this.

http://192.x.x.x/Demo/Service1.svc/GetData

http://192.x.x.x/Demo/Service1.svc/ProductDetails?prodId=P2

now i want to use these methods in Iphone.

& i call them as-

NSDictionary *arrayDict=[[NSDictionary alloc]init];

NSString *requestString = [NSString stringWithFormat:@"%@", [arrayDict JSONFragment], nil];
NSData *requestData = [NSData dataWithBytes: [requestString UT开发者_如何学PythonF8String] length: [requestString length]];    
NSString *url = [NSString stringWithFormat:@"http://192.x.x.x/Demo/Service1.svc/ProductDetails/prodId=%@",@"P2"];
NSLog(@"URL %@",url);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]];
[request setHTTPMethod: @"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

SO please tell me how to call this method[ProductDetails(string ProdId)] in Iphone


Check this out: Calling WCF Service from iPhone

http://knowledgebaseworld.blogspot.com/2010/06/calling-wcf-service-from-iphone.html


I would make it an Rest Endpoint on the Service. That makes calling it, specially from other systems like the IPhone much easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜