简体   繁体   English

具有多个端点的WCF服务的HTTP错误请求(400)错误

[英]HTTP Bad Request (400) Error with a WCF Service with Multiple Endpoints

I have written a WCF service with the following configuration: 我编写了具有以下配置的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>

On the client, I am building the proxy to consume the service dynamically: 在客户端上,我正在构建代理以动态使用服务:

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());
        }

Initially, I had only the DataBinding endpoint, residing at the default address (not the DataBinding address it currently does) and I used the same client side code to consume that service endpoint and everything worked correctly. 最初,我只有DataBinding端点,它位于默认地址(而不是它当前使用的DataBinding地址),并且我使用相同的客户端代码来使用该服务端点,并且一切正常。 When I added the FileBinding endpoint and moved the DataBinding endpoint to its new location http://localhost/SyncService.svc/DataBinding I was no longer able to connect to either endpoint and instead received a "Bad Request (400)" the first time it was used. 当我添加FileBinding终结点并将DataBinding终结点移动到其新位置http://localhost/SyncService.svc/DataBinding我不再能够连接到任一终结点,而是第一次收到“错误请求(400)”它被使用了。

Looking at the Service Trace Viewer, I see the following additional information about the System.Xml.XmlException being thrown: 查看服务跟踪查看器,我看到有关抛出System.Xml.XmlException的以下其他信息:

There is a problem with the XML that was received from the network. 从网络接收到的XML存在问题。 See inner exception for more details. 有关更多详细信息,请参见内部异常。

Inner Exception: 内部异常:

The body of the message cannot be read because it is empty. 邮件的正文为空,因此无法读取。

Stack Trace: 堆栈跟踪:

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)

When I view SyncService.svc in a browser, I get the "You have created a service" page and everything looks correct. 当我在浏览器中查看SyncService.svc时,出现“您已创建服务”页面,并且一切看起来正确。 The wsdl also looks appropriate. wsdl看起来也很合适。 When I go to http://localhost/SyncService.svc/FileBinding a blank page is loaded (in contrast to an error page when I go to something like http://localhost/SyncService.svc/XXX ). 当我转到http://localhost/SyncService.svc/FileBinding将加载一个空白页面(与之相比,当我转到类似http://localhost/SyncService.svc/XXX的错误页面时)。

I have waded through a number of similar issues, to no avail, including: 我经历了许多类似的问题,但都无济于事,包括:

HTTP Bad Request error when requesting a WCF service contract 请求WCF服务合同时出现HTTP错误请求错误

Large WCF web service request failing with (400) HTTP Bad Request 大型WCF Web服务请求失败,并显示(400)HTTP错误请求

Anyone have any thoughts or suggestions on how to resolve this? 有人对如何解决此问题有任何想法或建议吗?

As it turns out, this issue was caused not by the contract object but by an object it REFERENCED not being found. 事实证明,此问题不是由合同对象引起的,而是由未找到“参考”的对象引起的。 In my case, I had forgot to install all of the required Microsoft Sync Framework pieces on the server. 就我而言,我忘记在服务器上安装所有必需的Microsoft Sync Framework件。

I guess the moral of the story is that this error is pretty misleading and applies to all child objects as well! 我想这个故事的寓意是,此错误相当容易引起误解,并且也适用于所有子对象!

Can you try to inspect the request being sent to the server using tools like Fiddler. 您是否可以尝试使用Fiddler之类的工具检查发送到服务器的请求。 There must be something in the soap envelop that is causing the issue. 肥皂信封中一定有引起问题的东西。

Also try to send small data initially to make sure your service is accessible and then try to larger data so that you can narrow down on where the problem is. 另外,尝试首先发送小数据以确保您的服务可访问,然后再尝试发送大数据,以便缩小问题范围。

Have you implemented the async pattern or is your web service marked as Async=True. 您是否实现了异步模式,或者您的Web服务被标记为Async = True。

Would be helpful if you can post your service as well. 如果您也可以发布服务会很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM