我正在使用IOS 8开发一个应用程序,我在其中使用SOAP服务将数据保存到服务器。
如果我的方法名称字符串长度小于65535,则服务正常并获得响应。
如果我的方法名称字符串长度大于65535,那么我没有收到服务器的任何响应。
这是代码。
-(void)fetchDataFromURL:(NSString *)finalURL withMethodName:(NSString *)methodName withType:(NSString *)methodType migrationCompletionHandler:(void(^)(BOOL resultValue, NSData *responseData, NSString *internetStatus, NSError * error))completionBlock
{
someActionHandler = completionBlock;
reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
//Web Service Call
if (internetStatus != NotReachable)
{
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<SOAP-ENV:Envelope \n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
"<SOAP-ENV:Body> \n"
"%@\n"
"</SOAP-ENV:Body> \n"
"</SOAP-ENV:Envelope>",finalURL];
NSURL *url = [NSURL URLWithString:@"myURLString"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:25];
NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];
[theRequest setValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSString *method=[NSString stringWithFormat:@"http://Namespace%@",methodName];
[theRequest setValue:method forHTTPHeaderField:@"Soapaction"];
[theRequest setValue:@"chunked" forHTTPHeaderField:@"transfer-coding"];
[theRequest setValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:methodType];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSError * error = nil;
NSURLResponse * response = nil;
NSData * data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
if (error)
{
completionBlock(FALSE,nil,@"YES",error);
}
else
{
completionBlock(TRUE, data,@"YES",nil);
}
}
else
{
completionBlock(FALSE,nil, @"NO", nil);
}
}