0

嘿嘿,

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

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

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

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

该服务托管在http://localhost:50666/MyService.Foo/BarServiceHttp(使用 base-address 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>
4

1 回答 1

0

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

http://localhost:50666/MyService.Foo
于 2013-01-24T00:27:10.753 回答