我已经制作了一个WCF服务(service1.svc)有两种方法。
1.GetData()
2.ProductDetails(string ProdId)
当我这样做时,两者都以JSON格式返回文件。
http://192.x.x.x/Demo/Service1.svc/GetData
http://192.x.x.x/Demo/Service1.svc/ProductDetails?prodId=P2
现在我想在Iphone中使用这些方法。
&安培;我把它们称为 -
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];
请告诉我如何在Iphone中调用此方法[ProductDetails(string ProdId)]
答案 0 :(得分:2)
检查一下:从iPhone调用WCF服务
http://knowledgebaseworld.blogspot.com/2010/06/calling-wcf-service-from-iphone.html
答案 1 :(得分:1)
我会把它作为服务的休息终点。 这使得调用它,特别是来自其他系统,如iPhone更容易。