tags:

views:

47

answers:

2

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 UTF8String] 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

+1  A: 

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

cRichter
But How i will do this...??
Just search google, http://msdn.microsoft.com/en-us/netframework/dd547388.aspxthere is a lot of information out there what you have to do to change it. but its not just change binding. sorry.
cRichter
+2  A: 

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

Imran

IBhadelia
Great example code - thanks!
John Sibly
But i want to call a method that has an argumenti.e. ProductDetails(string ProdId)the method without any argument is working for me also.Anyways Thanks....but hope you will answer this.
You can add that into your soap header, your header will get change. in my example if there is need to pass one parameter name startsWith which is string then the envelope should look like following<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><GetDictionary><startsWith>I</startsWith></GetDictionary></SOAP-ENV:Body></SOAP-ENV:Envelope>
IBhadelia
Thanks i have done this.