Send image to asp.net web service from IOS

懵懂的女人 提交于 2019-12-19 04:10:38

问题


In my IOS app i need o send a image to ASP.NET Web Service . I am trying to the image in bytes form & then convert it back to image form on server side. Now i am using these line to convert image to bytes in IOS :

 NSData *imageData=UIImagePNGRepresentation([Mybutton currentBackgroundImage]);

this line give a bytes of 734,775 word, which is too much, so it can not be send a soap request . So , now how can i acieve this goal ??????

when call the service usiong soap request then it gives me this error :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>      System.Web.Services.Protocols.SoapException:
   There was an exception running the extensions specified in the config file. ---&gt; System.Web.HttpException: Maximum request length exceeded.
           at System.Web.HttpRequest.GetEntireRawContent()
          at System.Web.HttpRequest.get_InputStream()
         at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
         --- End of inner exception stack trace ---
       at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
         at    System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type,             HttpContext context, HttpRequest request, HttpResponse              response, Boolean&amp; abortProcessing)
</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>

I am making an app for chating , so on registeration of user i have to upload the user image to web server and when it search for people around him/her, then also i want to return imae from the web service how can i do thse two things ? First put image on web server & then retrieve from web server . Thanks A lot


回答1:


  • You can reduce the memory footage of the image using JPEG image compression

    lowResolutionImage = [UIImage imageWithData:UIImageJPEGRepresentation(highResImage, quality)];
    

    where quality is between 0.0 and 1.0

  • Don't send the image as raw binary over the internet turn the binary into base64 string

because some media are made for streaming text. You never know some protocols may interpret your binary data as control characters , or your binary data could be screwed up because the underlying protocol might think that you've entered a special character combination.

Here is the link on how to convert into base64

  • As you are using IIS for hosting your application, then the default upload file size if 4MB. To increase it, please use this below section in your web.config

    <configuration>
        <system.web>
            <httpRuntime maxRequestLength="1048576" />
        </system.web>
    </configuration>
    

    For IIS7 and above, you also need to add the lines below:

    <system.webServer>
       <security>
          <requestFiltering>
           <requestLimits maxAllowedContentLength="1073741824" />
          </requestFiltering>
      </security>
    

Note: maxAllowedContentLength is measured in bytes while maxRequestLength is measured in kilobytes, which is why the values differ in this config example. (Both are equivalent to 1 GB.)

Here is an answer for another question that'd be helpful to you



来源:https://stackoverflow.com/questions/28861220/send-image-to-asp-net-web-service-from-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!