【发布时间】:2012-05-08 07:37:09
【问题描述】:
我最近在使用某种网络方法时遇到了相当大的问题:
void CheckGfiHelpdesks(string ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks)
我一直在用这段代码调用那个方法:
List<GfiCheck> newFailedChecks = new List<GfiCheck>();
List<GfiCheck> otherFailedChecks = new List<GfiCheck>();
//do some work, create new GfiCheck items, fill the lists
Webclient.CheckGfiHelpdesks(Ticket, newFailedChecks.ToArray(), otherFailedChecks.ToArray());
newFailedChecks 和 otherFailedChecks 是列表。当该方法作为 SOAP 服务在 IIS 上运行时,这一直运行良好。
但是,在我将完全相同的方法复制到 WCF 服务后,调用产生了“400 bad request”异常。
最终我发现 .ToArray() 确实是问题所在。这个:
Webclient.CheckGfiHelpdesks(Ticket, newFailedChecks.ToArray<GfiCheck>(), otherFailedChecks.ToArray<GfiCheck>());
即使用System.Linq.Enumerable.ToArray<T>() 而不是System.Collections.Generic.List<T>.ToArray() 最终解决了问题并且异常消失了。
对这种差异的解释是什么?数组是数组,但显然不是?
确切的例外是:
System.ServiceModel.ProtocolException
远程服务器返回了意外响应:(400) Bad Request。
堆栈跟踪:
服务器堆栈跟踪:
在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest 请求,HttpWebResponse 响应,HttpChannelFactory 工厂,WebException responseException,ChannelBinding 通道绑定)
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan 超时)
在 System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan 超时)
在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan 超时)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime 操作)
在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)
>
在 [0] 处重新抛出异常:
在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型)
在 MonitoringService.BL.CentronService.ICentronService.CheckGfiHelpdesks(String ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks)
在 C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.BL\Service 中的 MonitoringService.BL.CentronService.CentronServiceClient.CheckGfiHelpdesks(String ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks) References\CentronService\Reference.cs:Zeile 5368。
在 C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.BL\ConnectorBL.cs:Zeile 120 中的 MonitoringService.BL.ConnectorBL.CheckHelpdesks(List`1 clients)。
在 C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\MainForm.cs:Zeile 124 中的 MonitoringService.WinForm.MainForm.LoadChecks()。
在 C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\MainForm.cs:Zeile 114 中的 MonitoringService.WinForm.MainForm.btnLoad_Click(Object sender, EventArgs e)。
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e)
在 DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message&m)
在 DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
在 DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
在 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 原因,ApplicationContext 上下文)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\Program.cs:Zeile 22 中的 MonitoringService.WinForm.Program.Main()。
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
at 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()
【问题讨论】:
-
我想你很困惑,没有
System.Linq.ToArray<T>()或System.Collections.Generic.ToArray()。 -
另外,您能否发布来自服务的完整异常消息和堆栈跟踪?
-
@RowlandShaw 是的,我编辑了这个问题。
标签: c# wcf linq web-services soap