嘿嘿,
我觉得自己像个彻头彻尾的白痴,但我似乎找不到答案。
我在控制台应用程序中自托管 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>