我一直在尝试将旧版 WSE 3 Web 服务移植到 WCF。由于保持与 WSE 3 客户端的向后兼容性是目标,因此我遵循了此 article 中的指导。 .
经过多次尝试和错误,我可以从 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 tracing tool并打开日志文件。可能发生了一些异常。
-- 编辑--
嗯,这是一个有趣的错误消息。它会带来更多 Google 结果:
关于.net - 尝试将 Web 引用添加到 WCF 服务时出现 HTTP 400 错误请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2908654/