【问题标题】:Send image to asp.net web service from IOS将图像从 IOS 发送到 asp.net Web 服务
【发布时间】:2015-03-04 17:41:58
【问题描述】:

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

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

这一行给出了734,775字的字节,太多了,所以不能发送soap请求。 那么,现在我该如何实现这个目标??????

当使用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 我该怎么做这两件事? 首先将图像放在网络服务器上,然后从网络服务器检索。 非常感谢

【问题讨论】:

  • 嗨,您找到问题的解决方案了吗?如果是这样,请帮助我解决这个问题。 stackoverflow.com/questions/29077775/…
  • @pasha pash - 我也面临同样的问题,下面的答案是我为解决问题所做的。如果您的问题仍未解决,请随时与我联系

标签: ios asp.net web-services soap


【解决方案1】:
  • 您可以使用 JPEG 图像减少图像的内存片段 压缩

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

    质量介于 0.0 和 1.0 之间

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

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

这里是link关于如何转换成base64

  • 当您使用 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 另一个对您有帮助的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多