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!