远程服务器返回意外响应:(400) Bad Request
Posted
技术标签:
【中文标题】远程服务器返回意外响应:(400) Bad Request【英文标题】:The remote server returned an unexpected response: (400) Bad Request 【发布时间】:2011-05-13 14:36:10 【问题描述】:我收到此错误“远程服务器返回意外响应:(400) 错误请求。”。 即使在 *** 上,我也查看了很多线程并尝试了这些解决方案,但它们对我不起作用......比如增加超时和缓冲区大小......
这是我在服务器上的代码..
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
BasicHttpBinding basichttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
basichttpbinding.CloseTimeout=TimeSpan.MaxValue;
basichttpbinding.OpenTimeout=TimeSpan.MaxValue;
basichttpbinding.ReceiveTimeout=TimeSpan.MaxValue;
basichttpbinding.SendTimeout=TimeSpan.MaxValue;
// basichttpbinding.TransferMode = TransferMode.Buffered;
ServiceEndpoint servicepoint=new ServiceEndpoint(ContractDescription.GetContract(serviceType));
servicepoint.Binding=basichttpbinding;
ServiceHost servicehost = new ServiceHost(serviceType, baseAddresses);
((ServiceDebugBehavior)servicehost.Description.Behaviors[typeof(ServiceDebugBehavior)]).IncludeExceptionDetailInFaults=true;
servicehost.OpenTimeout = TimeSpan.MaxValue;
servicehost.CloseTimeout = TimeSpan.MaxValue;
servicepoint.Binding.SendTimeout = TimeSpan.MaxValue;
servicepoint.Binding.ReceiveTimeout = TimeSpan.MaxValue;
basichttpbinding.MaxBufferPoolSize = 999999999;
// basichttpbinding.MaxConnections = 999999999;
//basichttpbinding.MaxConnections = 999999999;
basichttpbinding.MaxReceivedMessageSize = 999999999;
XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
quotas.MaxArrayLength = 999999999;
quotas.MaxBytesPerRead = 999999999;
quotas.MaxDepth = 999999999;
quotas.MaxNameTableCharCount = 999999999;
quotas.MaxStringContentLength = 999999999;
basichttpbinding.ReaderQuotas = quotas;
//foreach (Uri uri in baseAddresses)
//
servicehost.AddServiceEndpoint(typeof(IService), basichttpbinding, "");
//
return servicehost;
这是我在客户端使用的代码..
static void Main(string[] args)
BasicHttpBinding basichttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
ServiceEndpoint endpoint=new ServiceEndpoint(ContractDescription.GetContract(typeof(IService)));
endpoint.Binding=basichttpbinding;
basichttpbinding.CloseTimeout = TimeSpan.MaxValue;
basichttpbinding.OpenTimeout = TimeSpan.MaxValue;
basichttpbinding.ReceiveTimeout = TimeSpan.MaxValue;
basichttpbinding.SendTimeout = TimeSpan.MaxValue;
basichttpbinding.TransferMode = TransferMode.Streamed;
endpoint.Binding.SendTimeout = TimeSpan.MaxValue;
endpoint.Binding.ReceiveTimeout = TimeSpan.MaxValue;
basichttpbinding.MaxBufferPoolSize = 999999999;
// basichttpbinding.MaxConnections = 999999999;
//basichttpbinding.MaxConnections = 999999999;
basichttpbinding.MaxReceivedMessageSize = 999999999;
XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
quotas.MaxArrayLength = 999999999;
quotas.MaxBytesPerRead = 999999999;
quotas.MaxDepth = 999999999;
quotas.MaxNameTableCharCount = 999999999;
quotas.MaxStringContentLength = 999999999;
basichttpbinding.ReaderQuotas = quotas;
EndpointAddress address=new EndpointAddress("http://localhost:52855/WCFService1/Service.svc");
ChannelFactory<IService> objClient = new ChannelFactory<IService>(basichttpbinding,address);
IService obj = objClient.CreateChannel(address);
obj.GetData(1);
请帮帮我.. 谢谢..
编辑:请不要说“使用配置文件”等。我这样做只是因为我别无选择,必须这样做。谢谢
编辑:追踪后的更多详细信息...
</PRE>This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:</DIV></BODY></html></MessageLogTraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>262164</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2011-05-14T07:42:42.6268846Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="927d4271-a71b-43e6-a8c8-b5b69f5a1b4d" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="6" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Channels.MessageSent.aspx</TraceIdentifier><Description>Sent a message over a channel.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><Source>System.ServiceModel.Activation.HostedHttpContext+HostedRequestHttpOutput/65311427</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord"><MessageProperties><Encoder>application/xml; charset=utf-8</Encoder><AllowOutputBatching>False</AllowOutputBatching></MessageProperties><MessageHeaders></MessageHeaders></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-05-14T07:42:42.6278847Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="927d4271-a71b-43e6-a8c8-b5b69f5a1b4d" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="6" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Process action ''.</ActivityName><ActivityType>ProcessAction</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>262168</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2142614Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Channels.ConnectToIPEndpoint.aspx</TraceIdentifier><Description>Connection information.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><Source>System.ServiceModel.Activation.HostedHttpTransportManager/5669220</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><LocalEndpoint>::1:52855</LocalEndpoint><RemoteEndpoint>::1:0</RemoteEndpoint></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2142614Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" RelatedActivityID="91bc1c27-5688-4e02-956b-48a9a7e6872c" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Suspend">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2142614Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Suspend"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Listen at 'http://localhost:52855/WCFService1/Service.svc'.</ActivityName><ActivityType>ListenAt</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Start">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2142614Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="91bc1c27-5688-4e02-956b-48a9a7e6872c" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Start"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Processing message 2.</ActivityName><ActivityType>ProcessMessage</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2142614Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="91bc1c27-5688-4e02-956b-48a9a7e6872c" RelatedActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2142614Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="91bc1c27-5688-4e02-956b-48a9a7e6872c" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Processing message 2.</ActivityName><ActivityType>ProcessMessage</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Resume">0</SubType><Level>255</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2142614Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Resume"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ActivityBoundary.aspx</TraceIdentifier><Description>Activity boundary.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord"><ActivityName>Listen at 'http://localhost:52855/WCFService1/Service.svc'.</ActivityName><ActivityType>ListenAt</ActivityType></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131075</EventID><Type>3</Type><SubType Name="Error">0</SubType><Level>2</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2172616Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier><Description>Throwing an exception.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><Exception><ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>There is a problem with the XML that was received from the network. See inner exception for more details.</Message><StackTrace> at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace><ExceptionString>System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---&gt; System.Xml.XmlException: The body of the message cannot be read because it is empty.
--- End of inner exception stack trace ---</ExceptionString><InnerException><ExceptionType>System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The body of the message cannot be read because it is empty.</Message><StackTrace> at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace><ExceptionString>System.Xml.XmlException: The body of the message cannot be read because it is empty.</ExceptionString></InnerException></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>262164</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2011-05-14T07:42:49.2912658Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Channels.MessageSent.aspx</TraceIdentifier><Description>Sent a message over a channel.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><Source>System.ServiceModel.Activation.HostedHttpContext+HostedRequestHttpOutput/2389992</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord"><MessageProperties><AllowOutputBatching>False</AllowOutputBatching></MessageProperties><MessageHeaders></MessageHeaders></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131076</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2011-05-14T07:42:49.3462690Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="a38d441f-464e-4816-a084-8d6c8b484b59" /><Execution ProcessName="WebDev.WebServer40" ProcessID="4596" ThreadID="9" /><Channel/><Computer>UNIQUETOP</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.TraceHandledException.aspx</TraceIdentifier><Description>Handling an exception.</Description><AppDomain>46847491-1-129498325594327019</AppDomain><Exception><ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>There is a problem with the XML that was received from the network. See inner exception for more details.</Message><StackTrace> at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)</StackTrace><ExceptionString>System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---&gt; System.Xml.XmlException: The body of the message cannot be read because it is empty.
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)</ExceptionString><InnerException><ExceptionType>System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The body of the message cannot be read because it is empty.</Message><StackTrace> at System.ServiceModel.Diagnostics.ExceptionUtility.TraceHandledException(Exception exception, TraceEventType eventType)
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
【问题讨论】:
如果您无法解决问题,您可能应该启用调试日志记录/跟踪并发布有关您的问题的更多详细信息。 @avid,启用日志记录和跟踪后,我现在已经发布了跟踪记录。 如果您只是从跟踪中发布错误而不是那些巨大的混乱,您可能会有更多的运气。 @Nathan 你的意思是使用 svctraceviewer 工具吗? 【参考方案1】:从您发布的代码来看,鉴于 URI 中的 .svc 扩展名,您的客户端似乎希望与 IIS 托管服务进行交互:
EndpointAddress address=new EndpointAddress("http://localhost:52855/WCFService1/Service.svc");
您没有说明您的服务是 IIS 托管还是自托管,但您确实说过配置文件不是一个选项。我看到了解决您遇到的问题的两种方法:
IIS 托管
为了在 IIS 下以编程方式配置 ServiceHost,您需要:
一个。实现您自己的派生自 ServiceHost 和 ServiceHostFactory 的类。
b.将代码内嵌在 .svc 文件中。
如果您选择实现自己的派生 ServiceHost 和 ServiceHostFactory 类,则需要在 .svc 文件的 @ServiceHost 标记中指定您的 ServiceHostFactory 派生类。
自托管
-
在您的服务器代码中,为 AddServiceEndpoint 方法调用中的每个端点指定一个 URI。
在您的客户端代码中,在创建通道时将相同的 URI 传递给 ChannelFactory。
在这种情况下,您将没有 .svc 文件。
完成后不要忘记关闭客户端上的代理 - 特别是在您使用 IIS 时。
我希望这可以帮助您指明正确的方向。如果您需要更多信息,请尽管询问。
【讨论】:
Tim,我比较了在引用我的 wcf 服务器时自动生成的 webconfig 设置,发现我需要在客户端上包含更多设置。以上是关于远程服务器返回意外响应:(400) Bad Request的主要内容,如果未能解决你的问题,请参考以下文章
远程服务器返回了意外响应:(400) Bad Request WCF REST
WCF LIST 传输大数据,远程服务器返回了意外响应 400