iphone.netiosweb-servicesasiformdatarequest

ASIFormDataRequest image upload via .net Bad Request


I've been trying to get my app to send image data as base 64 to a .net web service which converts it back to an image and saves it on the server.

This works fine for a tiny 10px x 10px image but for anything else i get a bad request response from the server. Here's my code. I'm doing it as xml as i cannot get postValue to work either.

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[reqstring setString:@"<Files xmlns=\"http://schemas.datacontract.org/2004/07/FileUpload\">"];
[reqstring appendString:@"<filename>"];
[reqstring appendString:@"/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2Ni4xNDU2NjEsIDIwMTIvMDIvMDYtMTQ6NTY6MjcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI"];
[reqstring appendString:@"</filename></Files>"];

[request appendPostData:[reqstring dataUsingEncoding:NSUTF8StringEncoding]];

[request setValidatesSecureCertificate:NO];
[request addRequestHeader:@"Content-Type" value:@"text/xml"];

[request setDelegate:self];

[request setDidFinishSelector:@selector(requestUploadFinished:)];
[request setDidFailSelector:@selector(requestUploadFailed:)];
[request startSynchronous];

Is there a limit to what can be sent this way or anything on the server that needs changing ?

Any good tutorials on this kind of thing ?

Any help would be greatly appreciated


Solution

  • Finally managed to resolve this. The xml limit was being reached in the request.

    My web.config needed correcting on the server. I set the binding type to webHttpBinding and added readerQuotas to solve it.

    <readerQuotas maxDepth="3200" maxStringContentLength="2147483647" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    

    Using tracing on the service helped a lot in this.

    <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
              <listeners>
               <add name="traceListener" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "C:\Traces.svclog" />
              </listeners>
           </source>
      </sources>