我编写了一个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
任何人对如何解决此问题有任何想法或建议?
答案 0 :(得分:1)
事实证明,这个问题不是由合同对象造成的,而是由未找到REFERENCED的对象引起的。就我而言,我忘了在服务器上安装所有必需的Microsoft Sync Framework部分。
我想这个故事的寓意是这个错误非常具有误导性,并且适用于所有儿童对象!
答案 1 :(得分:0)
您是否可以尝试使用Fiddler等工具检查发送到服务器的请求。肥皂信封中必定存在引起问题的东西。
还尝试最初发送小数据以确保您的服务可访问,然后尝试更大的数据,以便缩小问题所在。
您是否实现了异步模式,或者您的Web服务是否标记为Async = True。
如果您也可以发布服务,将会很有帮助。