![](/img/trans.png)
[英]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.