.net - 尝试将 Web 引用添加到 WCF 服务时出现 HTTP 400 错误请求错误

标签 .net wcf wse3.0

我一直在尝试将旧版 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 结果:

  1. Another stackoverflow question
  2. Could be fixed in next release of Windows 7
  3. TransferMode.StreamedResponse

关于.net - 尝试将 Web 引用添加到 WCF 服务时出现 HTTP 400 错误请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2908654/

相关文章:

c# - Win Forms UserControl 未检测到按键

c# - 调用基于异步任务的 WCF 方法是利用 I/O 完成端口还是线程池线程来调用延续?

c# - 从 WSE 3.0 客户端请求中删除 WS-Addressing/WS-Security 部分

visual-studio - WSE 客户端项目不断将 WebServicesClientProtocol 恢复为 SoapHttpClientProtocol

.net - 有没有办法检查用户当前是否空闲?

c# - 将硬盘路径转换为应用程序文件夹路径

c# - Log4net 没有在日志文件中写入任何内容

wcf - WCF 限制是否默认开启?

.net - 带有 WCF 的 JSON-P 示例?

wcf - 支持 WSE 3.0 吗?