8

我一直在尝试将旧版 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 没有认识到这是一个元数据请求。

4

2 回答 2

3

您可以尝试在服务器上启用 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 跟踪工具并打开日志文件。可能发生了一些异常。

- 编辑 -

嗯,这是一个有趣的错误信息。它导致更多的谷歌结果:

  1. 另一个stackoverflow问题
  2. 可以在 Windows 7 的下一个版本中修复
  3. TransferMode.StreamedResponse
于 2010-05-25T21:42:11.160 回答
0

我会做以下事情:

<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

于 2012-01-21T04:43:03.377 回答