Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload Image from iOS to WCF, error 415(unsupported media)
    primarykey
    data
    text
    <p>I'm trying to upload a photo taken by the iphone to the <strong>WCF RESTful server</strong>, i've looked all over the web for examples and other answers around the issue, but i can't give with the solution.</p> <p>The app is written in <strong>iOS6</strong>, and i'm using <strong>AFNetworking 2.0</strong> to upload the image. As in the simulator the camera doesn't work, i've been trying with a library photo. I think the problem is in format differences, <strong>WCF is requesting for a Stream parameter</strong>, and i don't know how AFNetworking is sending the info...</p> <p>Here is the <strong>WCF code:</strong></p> <pre><code>[WebInvoke(Method = "POST", UriTemplate = "FileUpload")] public void FileUpload(Stream stream) { try { byte[] buffer = new byte[10000]; stream.Read(buffer, 0, 10000); FileStream f = new FileStream("C:\\temp\\sample.jpg", FileMode.OpenOrCreate); f.Write(buffer, 0, buffer.Length); f.Close(); stream.Close(); System.Console.WriteLine("Recieved the image on server"); } catch (Exception e) { System.Console.WriteLine("ERROR: " + e.ToString()); } } </code></pre> <p><strong>iOS code:</strong></p> <pre><code>AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"foo": @"bar"}; NSURL *filePath = [NSURL fileURLWithPath:@"Users/juan/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE/IMG_0001.JPG"]; [manager POST:@"http://192.168.2.3:8732/wave/FileUpload" parameters:parameters constructingBodyWithBlock:^(id&lt;AFMultipartFormData&gt; formData) { [formData appendPartWithFileURL:filePath name:@"image" error:nil]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; </code></pre> <p>Testing the web service in <strong>fiddler</strong>, it throws the same error by sending an image, <strong>415 unsupported media</strong>.</p> <p>I let the <strong>app.config</strong> of the server:</p> <pre><code>&lt;configuration&gt; &lt;system.web&gt; &lt;httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true" executionTimeout="14400" /&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="WcfJsonRestService.waveWS"&gt; &lt;endpoint address="http://localhost:8732/wave" binding="wsHttpBinding" bindingConfiguration="wsHttp" contract="WcfJsonRestService.IWaveWS"/&gt; &lt;/service&gt; &lt;/services&gt; &lt;bindings&gt; &lt;wsHttpBinding&gt; &lt;binding name="wsHttp" maxReceivedMessageSize ="50000000" messageEncoding="Mtom" maxBufferPoolSize="50000000" &gt; &lt;readerQuotas maxArrayLength="50000000" /&gt; &lt;security mode="None" /&gt; &lt;/binding&gt; &lt;/wsHttpBinding&gt; &lt;/bindings&gt; &lt;/system.serviceModel&gt; &lt;system.diagnostics&gt; </code></pre> <p>Any idea or suggestion how to solve this? Every idea is welcome</p> <p><strong>EDIT:</strong> Finally i solved myself, the problem was in the app.config.</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;webHttpBinding&gt; &lt;binding name="WebConfiguration" maxBufferSize="65536" maxReceivedMessageSize="2000000000" transferMode="Streamed"&gt; &lt;/binding&gt; &lt;/webHttpBinding&gt; &lt;/bindings&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="WebBehavior"&gt; &lt;webHttp /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="WcfJsonRestService.waveWS"&gt; &lt;serviceMetadata httpGetEnabled="true" httpGetUrl="" /&gt; &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;services&gt; &lt;service name="WcfJsonRestService.waveWS"&gt; &lt;endpoint address="http://localhost:8732/wave" binding="webHttpBinding" behaviorConfiguration="WebBehavior" bindingConfiguration="WebConfiguration" contract="WcfJsonRestService.IWaveWS"/&gt; &lt;/service&gt; &lt;/services&gt; &lt;/system.serviceModel&gt; &lt;startup&gt; &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt; &lt;/startup&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload