WSE352:DimeFormatException异常的处理方法

      在应用中利用Web服务在数据库中检索数据生成DataSet对象,并传输给客户端。为了提高性能,使用GZipDataSet做压缩,并以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
原文地址:https://www.cnblogs.com/jeet/p/177754.html