WSE352:DimeFormatException異常的處理方法

來源:互聯網
上載者:User
      在應用中利用Web服務在資料庫中檢索資料產生DataSet對象,並傳輸給用戶端。為了提高效能,使用GZip對DataSet做壓縮,並以DimeAttachment作為附件的方式進行傳輸。我使用的是WSE 2.0 SP3,當傳輸的大資料量時,用戶端報錯,錯誤資訊是“未處理的“Microsoft.Web.Services2.Dime.DimeFormatException”類型的異常出現在 microsoft.web.services2.dll 中。其他資訊: WSE352: The size of the record uuid:db8c7b93-e775-4ebd-9292-17b78f8e79a6 exceed its limit. ”
    伺服器代碼如下(通過資料訪問組件訪問資料庫返回DataSet,並把DataSet以GZip壓縮後以DimeAttachment的方式返回給用戶端):
    

[WebMethod(Description="執行SQL語句或有傳回值的預存程序並返回DataSet,供.net用戶端調用,壓縮並以附件返回以提升效能")]
        public void GetDataSet(string logicalName,string commandText,bool isStoreProcedure,string paraList)
        {
            SoapContext sc = ResponseSoapContext.Current;
            if (null == sc)
            {
                throw new ApplicationException("Only SOAP requests allowed");
            }
            
           DataSet ds=DataHelper.ExecuteDataSet(logicalName,commandText,isStoreProcedure,paraList);
             
           MemoryStream memoryStream=new MemoryStream(2048);

           GZipOutputStream gzipStream=new GZipOutputStream(memoryStream);
           
           ds.WriteXml(gzipStream);
            gzipStream.Finish();

            memoryStream.Seek(0, SeekOrigin.Begin);

            DimeAttachment dimeAttachment = new DimeAttachment("application/x-gzip",
                TypeFormat.MediaType, 
                memoryStream);

            sc.Attachments.Add(dimeAttachment);
        }


         用戶端調用代碼(檢索WebService傳回來的DimeAttachment,解壓後填充DataSet,並綁定到DataGrid上):
 

private void getDataSet()
        {
            ds=new DataSet();
            DataAccess.DBServiceWse service=new DALPerformanceCompare.DataAccess.DBServiceWse();
            service.Timeout=-1;
            commandText=buildCommandText();
            
            this.Cursor=Cursors.WaitCursor;
                                 service.GetDataSet("Compare",commandText,false,null);
            


            SoapContext sc=service.ResponseSoapContext;


            GZipInputStream gzipInputStream = new GZipInputStream(sc.Attachments[0].Stream);
            MemoryStream ms = new MemoryStream(1024);
            int nSize = 2048;
            byte[] writeData = new byte[2048];

            while (true) 
            {
                nSize = gzipInputStream.Read(writeData, 0, nSize);
                if (nSize > 0) 
                    ms.Write(writeData, 0, nSize);
                else 
                    break;
            }
            
            
            ms.Seek(0, SeekOrigin.Begin);
            
            ds.ReadXml(ms);

            dataGrid1.DataSource=ds.Tables[0];
            this.Cursor=Cursors.Default;
        }

       在WSE的協助檔案裡尋找了一下,發現原來預設的DimeAttachment的大小是4096KB,大於4M的檔案傳輸需要在伺服器端的Web.config檔案與用戶端的app.config檔案做訊息大小的設定,在設定檔中加入下列節:
   

<configuration>
<microsoft.web.services2>
    <messaging>
       <maxRequestLength>128000</maxRequestLength>
    </messaging>
  </microsoft.web.services2>
</configuration>


      重新編譯後運行程式,正常返回大資料量的DataSet。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.