【问题标题】:how to call WCF Service method in Iphone如何在 Iphone 中调用 WCF 服务方法
【发布时间】:2011-03-13 08:17:57
【问题描述】:

我已经让 WCF 服务(service1.svc)有 2 种方法。

1.GetData()

2.ProductDetails(字符串 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)]

【问题讨论】:

    标签: iphone wcf


    【解决方案1】:

    【讨论】:

    • 但我想调用一个有参数的方法,即 ProductDetails(string ProdId) 没有任何参数的方法也适用于我。无论如何谢谢....但希望你能回答这个问题。
    • 您可以将其添加到您的肥皂标题中,您的标题将得到更改。在我的示例中,如果需要传递一个参数名称 startsWith ,它是字符串,那么信封应该如下所示 schemas.xmlsoap.org/soap/envelope\">I
    【解决方案2】:

    我会将其设为服务上的休息端点。 这使得调用它,特别是从其他系统(如 iPhone)更容易。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多