【发布时间】:2011-12-26 11:56:41
【问题描述】:
我写了一个 WCF 服务,配置如下:
<system.serviceModel>
<services>
<service name="SyncService" behaviorConfiguration="SyncServiceBehavior">
<endpoint name="DataBinding" address="/DataBinding" binding="wsHttpBinding" contract="ISyncService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint name="FileBinding" address="/FileBinding" binding="basicHttpBinding" bindingConfiguration="httpLargeMessageStream" contract="ISyncService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="httpLargeMessageStream" maxReceivedMessageSize="2147483647" transferMode="Streamed" messageEncoding="Mtom" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SyncServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
在客户端,我正在构建代理以动态使用服务:
private static RemoteFileProviderProxy CreateDynamicFileProxy(string endPointAddress)
{
//endPointAddress = http://localhost/SyncService.svc/FileBinding
BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "httpLargeMessageStream";
binding.TransferMode = TransferMode.Streamed;
binding.MessageEncoding = WSMessageEncoding.Mtom;
binding.MaxReceivedMessageSize = int.MaxValue;
ServiceEndpoint endPoint = new ServiceEndpoint(ContractDescription.GetContract (typeof(ISyncService)), binding, new EndpointAddress(endPointAddress));
endPoint.Name = "FileBinding";
ChannelFactory<ISyncService> channelFactory = new ChannelFactory<ISyncService>(endPoint);
return new RemoteFileProviderProxy((ISyncService)channelFactory.CreateChannel());
}
最初,我只有 DataBinding 端点,位于默认地址(不是它当前使用的 DataBinding 地址),我使用相同的客户端代码来使用该服务端点并且一切正常。当我添加 FileBinding 端点并将 DataBinding 端点移动到其新位置 http://localhost/SyncService.svc/DataBinding 时,我不再能够连接到任一端点,而是在第一次使用它时收到“错误请求 (400)”。
查看服务跟踪查看器,我看到以下有关引发 System.Xml.XmlException 的附加信息:
从网络接收的 XML 存在问题。有关详细信息,请参阅内部异常。
内部异常:
无法读取邮件正文,因为它是空的。
堆栈跟踪:
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)
当我在浏览器中查看 SyncService.svc 时,我看到“您已创建服务”页面并且一切看起来都正确。 wsdl 看起来也很合适。当我转到 http://localhost/SyncService.svc/FileBinding 时,会加载一个空白页面(与转到 http://localhost/SyncService.svc/XXX 之类的内容时的错误页面相反)。
我已经解决了许多类似的问题,但无济于事,包括:
HTTP Bad Request error when requesting a WCF service contract
Large WCF web service request failing with (400) HTTP Bad Request
有人对如何解决这个问题有任何想法或建议吗?
【问题讨论】:
-
有趣的更新,即使在抛出错误请求时正在使用 FileBinding 的代理对象,服务跟踪查看器也会显示在 DataBinding 端点侦听的错误。通过翻转端点出现在服务器配置文件中的顺序,我可以在 FileBinding 端点监听时抛出相同的错误。
-
从配置中的地址属性中删除斜线有什么影响吗?
-
@degorolls,没有。我已经尝试了两种方法并得到完全相同的结果。