0

I have xml string. It's wrong string. But after using NSLog and coping it from console, it became good string (I got good response from server). I build wrong string by this way:

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:enc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns0=\"http://com.test/types/AstoriaObjectProperties\" xmlns:ns1=\"http://com.test/wsdl/AstoriaObjectProperties\" xmlns:ns2=\"http://java.sun.com/jax-rpc-ri/internal\"><env:Body><ns1:setObjectProperties env:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><HashMap_1 xsi:type=\"ns2:hashMap\" enc:arrayType=\"ns2:mapEntry[2]\"><item xsi:type=\"ns2:mapEntry\"><key xsi:type=\"xsd:string\">id</key><value xsi:type=\"xsd:string\">%@</value></item><item xsi:type=\"ns2:mapEntry\"><key xsi:type=\"xsd:string\">annotations</key><value href=\"#ID1\"/></item></HashMap_1><HashMap_2 xsi:type=\"ns2:hashMap\" enc:arrayType=\"ns2:mapEntry[2]\"><item xsi:type=\"ns2:mapEntry\"><key xsi:type=\"xsd:string\">id</key><value xsi:type=\"xsd:string\">%@</value></item><item xsi:type=\"ns2:mapEntry\"><key xsi:type=\"xsd:string\">annotations</key><value href=\"#ID2\"/></item></HashMap_2></ns1:setObjectProperties>%@%@</env:Body></env:Envelope>", fileID, fileID, arrayNewXML, arrayOldXML];

When I sent this message to the server, I got an error in response.

But then I use NSLog to see soapMessage, I copy it, and use soap message from buffer. It looks like this.

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://com.test/types/AstoriaObjectProperties" xmlns:ns1="http://com.test/wsdl/AstoriaObjectProperties" xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"><env:Body><ns1:setObjectProperties env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><HashMap_1 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID1"/></item></HashMap_1><HashMap_2 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID2"/></item></HashMap_2></ns1:setObjectProperties><ns0:ArrayOfhashMap id="ID1" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap><ns0:ArrayOfhashMap id="ID2" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap></env:Body></env:Envelope>

And after that I have response with no errors.

I seems, that NSLog fixed some problems with encoding. But how to solve this issues in my soapMessage? I tried:

soapMessage = [soapMessage stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
soapMessage = [soapMessage stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
soapMessage = [soapMessage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

That didn't help.

Paul T.
  • 4,938
  • 7
  • 45
  • 93
  • Are you using the text from console with the same code or standalone client ? – A-Live Sep 18 '12 at 12:39
  • I used the text from console with the same code – Paul T. Sep 19 '12 at 04:03
  • If the request with empty parameters should be valid i'd try to perform it to see whether that is a format literal or parameters problem. Then i'd try to strip as many parameters as possible (probably replacing the parameters of formatted string one by one with the console output, this way you must be able to narrow the problem). Also as you have `encoding="UTF-8"` tag i'd use parameters as `[fileID UTF8String] `, `[arrayNewXML UTF8String]`, etc. – A-Live Sep 19 '12 at 09:15

1 Answers1

0

I just guest the encoding, and manually deleted some bad symbols:

 NSMutableData *soapdata = [[[NSMutableData alloc] initWithData:[soapMessage dataUsingEncoding:NSNonLossyASCIIStringEncoding]] autorelease]; 
   soapMessage = [[[NSString alloc] initWithData:soapdata encoding:NSUTF8StringEncoding] autorelease];
   soapMessage = [soapMessage stringByReplacingOccurrencesOfString:@"\\ufffc" withString:@""];
   soapdata = [[[NSMutableData alloc] initWithData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]] autorelease];

And now it works!

Paul T.
  • 4,938
  • 7
  • 45
  • 93