void CheckGfiHelpdesks(string ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks)
我一直在使用以下代码调用该方法:
List newFailedChecks = new List();
List otherFailedChecks = new List();
//做一些工作,创建新的GfiCheck项,填充列表
Webclient.CheckGfiHelpdesks(Ticket, newFailedChecks.ToArray(), otherFailedChecks.ToArray());
newFailedChecks和otherFailedChecks都是List。当该方法在IIS上作为SOAP服务运行时,这一直运行得很好。
然而,在我将完全相同的方法复制到WCF服务中后,调用产生了“400 bad request”异常。
最终,我发现.ToArray()确实是问题所在。这个:
Webclient.CheckGfiHelpdesks(Ticket, newFailedChecks.ToArray(), otherFailedChecks.ToArray());
即使用System.Linq.Enumerable.ToArray()而不是System.Collections.Generic.List.ToArray()最终解决了问题,异常消失了。
这种差异的解释是什么?数组就是数组,但显然不是?
确切的异常是:
System.ServiceModel.ProtocolException 远程服务器返回了意外的响应:(400)错误请求。
堆栈跟踪:
服务器堆栈跟踪: 在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) 在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 在System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 在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 operation) 在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
异常在[0]处重新抛出:
在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)处
在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)处
在MonitoringService.BL.CentronService.ICentronService.CheckGfiHelpdesks(String ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks)处
在MonitoringService.BL.CentronService.CentronServiceClient.CheckGfiHelpdesks(String ticket, GfiCheck[] newHelpdeskChecks, GfiCheck[] otherChecks)位于C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.BL\Service References\CentronService\Reference.cs的第5368行。
在MonitoringService.BL.ConnectorBL.CheckHelpdesks(List`1 clients)位于C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.BL\ConnectorBL.cs的第120行。
在MonitoringService.WinForm.MainForm.LoadChecks()位于C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\MainForm.cs的第124行。
在MonitoringService.WinForm.MainForm.btnLoad_Click(Object sender, EventArgs e)位于C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\MainForm.cs的第114行。
在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 reason, ApplicationContext context)处
在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)处
在System.Windows.Forms.Application.Run(Form mainForm)处
在MonitoringService.WinForm.Program.Main()位于C:\Users\sohrm\documents\visual studio 2010\Projects\MonitoringService\MonitoringService.Client\Program.cs的第22行。
在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()处
System.Linq.ToArray<T>()
和System.Collections.Generic.ToArray()
都是不存在的。 - svick