我一直在尝试将旧版 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>
更新:在尝试保罗的跟踪建议后,我确定异常是System.Xml.XmlException: The body of the message cannot be read because it is empty
不幸的是,这似乎没有多大帮助。我注意到的另一件事是 serviceMetadata 元素有一个单独的 httpsGetEnabled 属性。我添加了它并将其设置为 true,因为这是一个 https 服务,但结果是一样的。似乎由于某种原因,WCF 没有认识到这是一个元数据请求。