SOAP service not responding if message length greater than 65535 in iOS8

别等时光非礼了梦想. 提交于 2019-12-08 05:15:42

问题


I am developing an app using IOS 8 in which I am using SOAP service to save data to server.

Service works fine and getting response if my method name string length is less than 65535.

If my method name string length is greater than 65535, then I am not getting any response from server.

Here is the code.

-(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);
    }
}

来源:https://stackoverflow.com/questions/32795507/soap-service-not-responding-if-message-length-greater-than-65535-in-ios8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!