iOS SOAP WCF调用问题 - HTTP 415错误

时间:2013-07-03 06:05:55

标签: ios wcf soap wsdl

我正在尝试发送SOAP请求,但它返回“HTTP 415不支持的媒体”错误。

下面给出的

是我的代码

NSString *soapMessage = [NSString stringWithFormat:@"<Envelope xmlns=\"http://www.w3.org/2003/05/soap-envelope\"><Body><GetCity xmlns=\"http://tempuri.org/\"><SearchString></SearchString><SearchZone></SearchZone></GetCity></Body></Envelope>"];



NSURL *url=[NSURL URLWithString:@"http://ws.abcxyz.com/abcxyz1/Service1.svc?wsdl"];

NSMutableURLRequest *theRequest= [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/IService1/GetCity" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if (theConnection) {

    NSMutableData *responseData = [NSMutableData data];
    NSLog(@"success %d", [responseData length]);
} else {
    NSLog(@"failed");
    //messageTextView.text=@"Failed";

}

如果我需要更改任何内容,请告诉我。

1 个答案:

答案 0 :(得分:2)

HTTP 415错误 - 不支持的媒体类型

服务器因为实体而拒绝为请求提供服务    请求采用所请求资源不支持的格式    对于要求的方法。