如下一个webservice方法:
/// <summary>
        /// 返回图片字节流
        /// </summary>
        [WebMethod(Description = "Function: use the data to get image byte stream")]
        public byte[] GetMapToBytes(List<PointZ> list, DateTime dateTime, MapType type)
        {
            IMapExport app = new MapExoport();          
            app.MapType= type;
            app.DateTime = dateTime;
            app.SetPoints(list);
            byte[] re = app.ExportMapStream();            LogUtils.Write(LogFileType.Information, string.Format("方法{0}返回byte[{1}].", "GetMapToBytes", re.Length.ToString()));
            
            return re;
        }我把这个webservice发布到了IIS服务器,使用.net客户端测试。客户端调用这个方法的时候,出错:未处理 System.Net.WebException
  Message=基础连接已经关闭: 接收时发生错误。
  Source=System.Web.Services
  StackTrace:
       在 System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
       在 System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
       在 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       在 Test.WebReference.ContourService.GetMapToBytes(PointZ[] list, DateTime dateTime, MapType type) 位置 E:\dn\trunk\com.dn.gisservice\Test\Web References\WebReference\Reference.cs:行号 89
       在 Test.Form1.btn_GetMapFrom21Server_Click(Object sender, EventArgs e) 位置 E:\dn\trunk\com.dn.gisservice\Test\Form1.cs:行号 105
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 Test.Program.Main() 位置 E:\dn\trunk\com.dn.gisservice\Test\Program.cs:行号 21
       在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.IO.IOException
       Message=无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。
       Source=System
       StackTrace:
            在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            在 System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            在 System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
       InnerException: System.Net.Sockets.SocketException
            Message=远程主机强迫关闭了一个现有的连接。
            Source=System
            ErrorCode=10054
            NativeErrorCode=10054
            StackTrace:
                 在 System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                 在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            InnerException: 请问这个错误是怎么回事?急。
从后台记录的日志来看, LogUtils.Write(LogFileType.Information, string.Format("方法{0}返回byte[{1}].", "GetMapToBytes", re.Length.ToString()));
这句已经执行了,为什么返回一个字节数据会失败呢??

解决方案 »

  1.   

    btye类型的流出现了问题。
    你可以考虑  先测试下 是不是文件没有进入byte中。   或者是不完成的文件进去了建议是本机测试一下。 然后放到服务器上去测一下。还有一种可能就是  没有那图片。  因为你的这段代码也没有catch块来获取错误信息。 
      

  2.   

    谢谢楼上,我在本机测试是成功的。我不知道是我的IIS出现了什么问题,有一次也出现了这个问题,重启之后,一切又正常了。
    过了几天时间,现在又这样了。
    查看IIS日志,发现里面记录的实际发送的字节数和应该发送的字节数不一样,相差很多,所以应该是IIS在发送数据的时候中断了连接,但是不知道是什么原因导致了连接的中断?大侠们帮帮忙,分析一下,是IIS BUG,内存泄露?还是其他的什么原因,现在我不知道怎么着手去分析这个问题了。