Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Monotouch和WCF,内存使用_.net_Wcf_Ipad_Memory Management_Xamarin.ios - Fatal编程技术网

.net Monotouch和WCF,内存使用

.net Monotouch和WCF,内存使用,.net,wcf,ipad,memory-management,xamarin.ios,.net,Wcf,Ipad,Memory Management,Xamarin.ios,我有WCF服务托管在网站和Monotouch应用程序,可以显示和更新服务中的PDF文档。PDF文件大小可以从1字节到20 Mb。 当我的文档很少时(少于100个,文档的总大小为30Mb),更新过程将成功完成。但是,当我有很多文档(超过300个,文档的一般大小是100Mb)时,我的程序会在iPad1上终止,但在iPad2上仍然可以工作 我认为内存使用中的问题。当我的应用程序使用了很多内存时,iOS杀死了它。但我不知道问题出在哪里,也许Monotouch GC没有清理fileData字节数组中的内存

我有WCF服务托管在网站和Monotouch应用程序,可以显示和更新服务中的PDF文档。PDF文件大小可以从1字节到20 Mb。 当我的文档很少时(少于100个,文档的总大小为30Mb),更新过程将成功完成。但是,当我有很多文档(超过300个,文档的一般大小是100Mb)时,我的程序会在iPad1上终止,但在iPad2上仍然可以工作

我认为内存使用中的问题。当我的应用程序使用了很多内存时,iOS杀死了它。但我不知道问题出在哪里,也许Monotouch GC没有清理fileData字节数组中的内存

在iPad上更新文档的方法:

protected bool BeginUpdateProcess()
{
  try {
    var binding = new BasicHttpBinding();
    binding.MaxBufferSize = 52428800;
    binding.MaxBufferPoolSize = binding.MaxReceivedMessageSize = 52428800L;
    binding.ReaderQuotas.MaxStringContentLength = binding.ReaderQuotas.MaxArrayLength = 52428800;
    var endpoint = new EndpointAddress(string.Format("http://{0}/Services/UpdateDataService.svc", UpdateInfo.Instance.ServerIP));
    using (var dataService = new UpdateDataServiceClient(binding, endpoint)) {
        // Get document list for update
        int[] docIds;
        try {
            docIds = dataService.GetModifiedDocumentIds(mLastUpdated);
        } catch (Exception ex) {
            LogWriter.Instance.WriteToLog("UpdateFromServiceEror: Can't load modified document ids list", ex);
            return false;
        }

        // Get each document content and save it to iPad
        for (int i = 0; i < docIds.Length; i++) {
            if (Canceled) {
                return true;
            }
            try {
                byte[] fileData = dataService.GetDocumentTransData(docIds[i]);
                SaveDocument(fileData);
            } catch (Exception ex) {
                LogWriter.Instance.WriteToLog(string.Format("Can't load or save file, id={0}", docIds[i]), ex);
                return false;
            }
        }
        dataService.Close();
    }
} catch (Exception ex) {
    LogWriter.Instance.WriteToLog("Error when update from service", ex);
}
 }
受保护的bool BeginUpdateProcess()
{
试一试{
var binding=新的BasicHttpBinding();
binding.MaxBufferSize=52428800;
binding.MaxBufferPoolSize=binding.MaxReceivedMessageSize=52428800L;
binding.ReaderQuotas.MaxStringContentLength=binding.ReaderQuotas.MaxArrayLength=52428800;
var endpoint=newendpointaddress(string.Format(“http://{0}/Services/UpdateDataService.svc”,UpdateInfo.Instance.ServerIP));
使用(var-dataService=newupdatedataserviceclient(绑定,端点)){
//获取要更新的文档列表
int[]docIds;
试一试{
docIds=dataService.getModifiedDocumentId(mLastUpdated);
}捕获(例外情况除外){
LogWriter.Instance.WriteToLog(“UpdateFromsServiceError:无法加载已修改的文档ID列表”,例如);
返回false;
}
//获取每个文档内容并将其保存到iPad
for(int i=0;i
网站WCF设置:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behaviors>
    <serviceBehaviors>
        <behavior name="Default">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

<bindings>
    <basicHttpBinding>
        <binding name="Transport"
            closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="52428800" maxBufferPoolSize="524288" maxReceivedMessageSize="52428800"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
            <readerQuotas maxDepth="64"
                        maxStringContentLength="52428800"
                        maxArrayLength="52428800"
                        maxBytesPerRead="16384"
                        maxNameTableCharCount="16384" />
        </binding>
    </basicHttpBinding>
</bindings>

<services>
    <service name="iDict.Site.Services.UpdateDataService" behaviorConfiguration="Default">
        <host>
            <baseAddresses>
                <add baseAddress="http://localhost:57709/Services/UpdateDataService.svc"/>
            </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Transport" contract="iDict.Site.Services.IUpdateDataService" />
    </service>
</services>


以下几点可能会对您有所帮助:

  • 52428800是设备的大缓冲区

  • PDF文档是否以XML格式传输?如果是这样的话,在某种程度上,您将同时拥有一个
    字符串
    (效率不高,内存方面)和一个
    字节[]文件数据
    。这可能会超过第一代iPad可用的RAM。避免这种情况的一种可能方法是使用将URL返回到文件的web服务。然后,可以轻松地将每个URL从web服务器流式传输到本地文件,而无需占用大量内存

  • iPad2有更多的RAM,上面提到的可能可以在上面使用,但对于较大的文档,这最终会失败。同时,使用
    将限制设备的存储空间

  • 根据您使用的MonoTouch版本,您可能正在使用。如果可以,我建议您尝试最新的MonoTouch版本(目前为beta版),它解决了这些问题


    • 以下几点可能会对您有所帮助:

      • 52428800是设备的大缓冲区

      • PDF文档是否以XML格式传输?如果是这样的话,在某种程度上,您将同时拥有一个
        字符串
        (效率不高,内存方面)和一个
        字节[]文件数据
        。这可能会超过第一代iPad可用的RAM。避免这种情况的一种可能方法是使用将URL返回到文件的web服务。然后,可以轻松地将每个URL从web服务器流式传输到本地文件,而无需占用大量内存

      • iPad2有更多的RAM,上面提到的可能可以在上面使用,但对于较大的文档,这最终会失败。同时,使用
        将限制设备的存储空间

      • 根据您使用的MonoTouch版本,您可能正在使用。如果可以,我建议您尝试最新的MonoTouch版本(目前为beta版),它解决了这些问题


      我不确定您所说的普通尺码是什么意思?对我来说,它看起来像是总大小,例如,当我只有很少的文档(小于100,文档的一般大小为30Mb)时,它就变成了总大小“当我只有不到100个文档,并且文档的总大小为30MB时……是的,你说得对。我更正了我的问题。我不知道你说的普通尺码是什么意思?对我来说,它看起来像总大小,例如,当我的文档很少(小于100,文档的一般大小为30Mb)时,它会变成“当我的文档很少,小于100,文档的总大小为30Mb…是的,你是对的。我更正了我的问题。