Question

In my app I am using a webservice that sign a document. I have to send the documento in base64format inside the SOAP call. The problem is that when I try to send a big document like a 11mb one, the base64 (stored in a NSString) is to large and the SOAP message is truncated.

Because of that I can send the SOAP call propertly and I recive a server error.

Is there any class that can store a large (very large) string?

EDIT: This is the code i've used:

To convert the document to base64:

NSData *signData = [[NSFileManager defaultManager] contentsAtPath:self.pathDocument];
NSString *base64file = [signData base64EncodedString];

To perform the call:

NSString *soapMsg = [NSString stringWithFormat:@"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\" xmlns:seal=\"http://schemas.datacontract.org/2004/07\">"
                   "<soapenv:Header/>"
                   "<soapenv:Body>"
                   "<tem:Sign>"
                   "<tem:type>Signature</tem:type>"
                   "<tem:biometricState>%@</tem:biometricState>"
                   "<tem:idCertificate>%d</tem:idCertificate>"
                   "<tem:signatureProfile>%@</tem:signatureProfile>"
                   "<tem:signatureType>Default</tem:signatureType>"
                   "<tem:hashAlgorithm>Default</tem:hashAlgorithm>"
                   "<tem:options>%@</tem:options>"
                   "<tem:signingDocument>%@</tem:signingDocument>"
                   "</tem:Sign>"
                   "</soapenv:Body>"
                   "</soapenv:Envelope>",
                   aSign,
                   [aCertificado idCert],
                   tipoFirma,
                   flagFirma,
                   aDocument
                   ];

NSString *stringURL = [NSString stringWithFormat:@"http://%@//Service/SignatureServiceBasic.svc", [settings servidor]];
    NSURL *sRequestURL = [NSURL URLWithString:stringURL];
    NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL];
    NSString *sMessageLength = [NSString stringWithFormat:@"%d", [soapMsg length]];

    [myRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [myRequest addValue:@"http://tempuri.org/ISignatureServiceBasic/Sign" forHTTPHeaderField:@"SOAPAction"];
    [myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"];
    [myRequest setHTTPMethod:@"POST"];
    [myRequest addValue:@"Jakarta Commons-HttpClient/3.1" forHTTPHeaderField:@"User-Agent"];
    [myRequest setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

    NSString* username = [settings usuario];
    NSString* password = [settings pass];

    NSString *authStr = [NSString stringWithFormat:@"%@:%@", username, password];
    NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
    NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodingWithLineLength:80]];
    [myRequest setValue:authValue forHTTPHeaderField:@"Authorization"];


    signConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self];

    if( signConnection ) {
        webResponseData = [NSMutableData data];
    }else {
        NSLog(@"Some error occurred in Connection");

    }

aDocument is the document in base64.

Thanks in advance!

Était-ce utile?

La solution 3

I've solved the problem. Sorry, I had misunderstood the problem. All my code was ok, the problem was due to a service parameter (in the IIS) that controls the maximum size of the files that can be uploaded.

Xcode crashed and failed on memory because the app was in debug mode. Without using the debugger, it does not.

Thanks to all!

Autres conseils

NO there is no such class.. but you can try 1 thing Try creating your data in chunks instead of a big file and send that data to server using streams..

You should send such large resource in form of attachments rather than as body of request. AFNetworking library provides ready to consume functions for same.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top