【问题标题】:Wcf self hosting over basicHttp and browsingWcf 通过 basicHttp 自托管和浏览
【发布时间】:2012-10-04 13:37:22
【问题描述】:

嘿嘿,

我觉得自己像个白痴,但我似乎找不到答案。

我在控制台应用程序中自托管 WCF 服务。 这就像一个魅力,我已经做了一百万次了:)

从另一个控制台应用程序或使用 wcftestclient 使用此服务完全没有问题。

但是当我尝试浏览服务时,我得到了“奇怪”的行为。

服务托管在http://localhost:50666/MyService.Foo/BarServiceHttp(基地址为http://localhost:50666/MyService.Foo)。

因此,当浏览到 http://localhost:50666/MyService.Foo/BarServiceHttp 时,浏览器会返回 HTTP 400 错误。

浏览基地址会得到我期望的完整地址的输出。

发生了什么事? (http后面的空格是为了绕过关于localhost的警告...)

这是服务器配置:

<service name="FooService" behaviorConfiguration="FooBarServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:50666/MyService.Foo" />
      </baseAddresses>
    </host>

    <endpoint address="BarServiceHttp"
              binding="basicHttpBinding"
              bindingConfiguration="basicHttpBindingConfiguration"
              contract="IBarService" />
    <endpoint address="BarServiceHttp/mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
</service>



<behavior name="FooBarServiceBehavior">
  <!-- Enable MEX http get for this service. -->
  <serviceMetadata httpGetEnabled="true"/>
  <serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>

【问题讨论】:

  • @CodeCaster 该设置在绑定配置中不可用。它是在我的服务行为配置中设置的,但我已将其排除在外,将调整有问题的服务器配置。

标签: wcf self-hosting


【解决方案1】:

您收到 HTTP 400 错误,因为您尝试直接访问端点。端点需要 SOAP 请求,但浏览器会发送 HTTP GET 请求,该请求无法由端点处理。您应该在浏览服务时使用基地址,因为您在浏览器中看到的元数据和帮助页面位于此处:

http://localhost:50666/MyService.Foo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2015-03-14
    相关资源
    最近更新 更多