从IOS发送图像到asp.net Web服务

时间:2015-03-04 17:41:59

标签: ios asp.net web-services soap

在我的IOS应用程序中,我需要将图像发送到ASP.NET Web Service。我正在尝试以字节形式和图像的图像然后将其转换回服务器端的图像格式。 现在我使用这些行在IOS中将图像转换为字节:

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

这一行给出734,775字的字节,这太多了,所以它不能发送一个soap请求。 所以,现在我怎样才能实现这个目标??????

当调用服务usiong soap请求时,它会给我这个错误:

<?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>

我正在制作一个用于聊天的应用程序,因此在注册用户时我必须将用户图像上传到网络服务器,当它搜索他/她周围的人时,我还想从网络服务返回imae 我怎么能做这两件事? 首先将图像放在Web服务器上;然后从Web服务器检索。 非常感谢

1 个答案:

答案 0 :(得分:3)

  • 您可以使用JPEG图像缩小图像的内存素材 压缩

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

    质量介于0.0和1.0之间

  • 不要通过互联网将图像作为原始二进制文件发送,将二进制文件转换为base64字符串

  

因为某些媒体是为流式文本而制作的。你永远不会知道一些   协议可能会将您的二进制数据解释为控制字符,或   你的二进制数据可能因为底层协议而搞砸了   可能会认为你输入了一个特殊的角色组合。

     

以下是有关如何转换为base64的link

  • 当您使用IIS托管应用程序时,默认上传文件大小为4MB。要增加它,请在web.config中使用以下部分

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

    对于IIS7及更高版本,您还需要添加以下行:

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

注意:maxAllowedContentLength以字节为单位测量,而maxRequestLength以千字节为单位,这就是此配置示例中值不同的原因。 (两者相当于1 GB。)

以下是另一个对您有帮助的问题的answer

相关问题