当前位置:编程学习 > C#/ASP.NET >>

IIS不能返回图片字节流,是什么原因呢?

如下一个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()));
这句已经执行了,为什么返回一个字节数据会失败呢?? --------------------编程问答-------------------- 是不是执行太慢,超时了? --------------------编程问答-------------------- 应该不是,我设置了很大的超时时间 --------------------编程问答-------------------- 内容序列化后太长, 把buffer设长.
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,