[英]Large WCF web service request failing with (400) HTTP Bad Request
[英]HTTP 400 Bad Request error attempting to add web reference to WCF Service
我一直在嘗試將傳統的WSE 3 Web服務移植到WCF。 由於保持與WSE 3客戶端的向后兼容性是我的目標,因此我遵循了本文中的指導。
經過多次試驗和錯誤,我可以從我的WSE 3客戶端調用WCF服務。 但是,我無法從Visual Studio 2005(安裝了WSE 3)添加或更新此服務的Web引用。 響應為“請求失敗,HTTP狀態為400:錯誤請求”。 我嘗試使用wsewsdl3實用程序生成代理時遇到同樣的錯誤。 我可以使用VS 2008添加服務引用。
我嘗試在Windows 7和Windows 2008 Server R2上的IIS 7.5中托管服務,結果相同。 任何解決方案或故障排除建
以下是我的WCF服務的配置文件中的相關部分。
<system.serviceModel>
<services>
<service behaviorConfiguration="MyBehavior"
name="MyService">
<endpoint address="" binding="customBinding" bindingConfiguration="wseBinding"
contract="IMyService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<customBinding>
<binding name="wseBinding">
<security authenticationMode="UserNameOverTransport" />
<mtomMessageEncoding messageVersion="Soap11WSAddressingAugust2004" />
<httpsTransport/>
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyCustomValidator" />
</serviceCredentials>
<serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="MyRoleProvider" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
更新:在嘗試了Paul的跟蹤建議后,我確定異常是System.Xml.XmlException:無法讀取消息正文,因為它是空的
不幸的是,這似乎沒有多大幫助。 我注意到的另一件事是serviceMetadata元素有一個單獨的httpsGetEnabled屬性。 我添加了它並將其設置為true,因為這是一個https服務,但結果是相同的。 似乎由於某種原因,WCF沒有意識到這是元數據請求。
您可以嘗試在服務器上啟用WCF跟蹤。 在</system.serviceModel>
行之前插入:
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog ="3000" />
</diagnostics>
在</system.serviceModel>
行之后插入:
<system.diagnostics>
<sharedListeners>
<add name="sharedListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\logs\tracelog.svclog" />
</sharedListeners>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" >
<listeners>
<add name="sharedListener" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add name="sharedListener" />
</listeners>
</source>
<source name="ApplicationLogging" switchValue="Information" >
<listeners>
<add name="sharedListener" />
</listeners>
</source>
</sources>
</system.diagnostics>
復制錯誤后,啟動WCF跟蹤工具並打開日志文件。 可能發生了一些異常。
- 編輯 -
嗯,這是一個有趣的錯誤信息。 它會帶來更多Google搜索結果:
我會做以下事情:
<serviceMetadata httpGetEnabled="true" />
改成:
<serviceMetadata httpsGetEnabled="true" />
也。 您是否設置了HTTPS綁定屬性: http : //blogs.msdn.com/b/wenlong/archive/2007/08/02/how-to-change-hostname-in-wsdl-of-an-iis-hosted -service.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.