当前位置:  开发笔记 > Android > 正文

请求WCF服务合同时出现HTTP错误请求错误

如何解决《请求WCF服务合同时出现HTTP错误请求错误》经验,为你挑选了1个好方法。

我有一个WCF服务,具有以下配置:


    
        
            
                
                
            
        
     
      
          
              
              
              
                  
                      
                  
              
          
    

WcfSvcHost.exe进程中托管服务时,如果我浏览到URL:

HTTP://本地主机/为MyService /合同

服务元数据可用的地方我收到HTTP 400 Bad Request错误.

通过检查WCF日志,我发现抛出了System.Xml.XmlException异常,并显示消息:" 无法读取消息正文,因为它是空的. "
以下是日志文件的摘录:



System.ServiceModel.ProtocolException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

There is a problem with the XML that was received from the network. See inner exception for more details.

at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, ItemDequeuedCallback callback)
at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCore(IAsyncResult result)
at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContext(IAsyncResult result)
at System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.ListenerAsyncResult.WaitCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)


System.Xml.XmlException, System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
The body of the message cannot be read because it is empty.

at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, ItemDequeuedCallback callback)
at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCore(IAsyncResult result)
at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContext(IAsyncResult result)
at System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.ListenerAsyncResult.WaitCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)



如果我改为浏览到URL:

HTTP://本地主机/ WSDL为MyService

一切正常,我得到了WSDL合同.此时,我还可以完全删除"MetadataHttp"元数据端点,它不会有任何区别.

我正在使用.NET 3.5 SP1.有没有人知道这里可能出现什么问题?



1> Enrico Campi..:

我想我发现了问题所在.

如果我浏览到URL:

HTTP://本地主机/为MyService /合同

使用WcfTestClient应用程序,我可以成功检索服务元数据.
因此,只有当我通过Web浏览器请求URL时才会出现错误.

HTTP错误的请求错误来自于一个事实,即浏览器发出HTTP GET请求,其中该消息的内容是在HTTP报头,身体是空的.
这正是WCF mexHttpBinding所抱怨的!

要通过Web浏览器获取服务合同,您必须在服务行为中明确启用它:


    
        
    

然后,请求的URL成为:

HTTP://本地主机/ WSDL为MyService

所以,事实证明我发布这个问题有点太快了.但是,我会保留它只是为了记录.

推荐阅读
李桂平2402851397
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有