【发布时间】:2010-07-20 10:08:44
【问题描述】:
我使用 C# 和 Visual Studio 2008 编写了一个 WCF Web 服务。
当我使用内置的开发 Web 服务器运行它时,我可以通过浏览到服务合同的 [WebGet(UriTemplate = "..")] 属性中指定的 URL 来查看各种方法的结果.
具体来说,我有一个匹配“/” URL 的方法,并返回一个纯 HTML 文件。
但是,当我部署到在 Windows Server 2008 上运行的 IIS 时,此方法会返回标准的“您已创建服务”页面。
如果我尝试使用我指定的 URI 模板执行任何其他方法,例如:
api.hostname.com/Service.svc/method/param
服务器返回 400 Bad Request。
我的 live web.config 的 system.serviceModel 部分如下所示:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="RootNamespace.Api.EventService"
behaviorConfiguration="RootNamespace.Api.EventServiceBehaviour" >
<endpoint address=""
binding="wsHttpBinding"
contract="RootNamespace.Api.IEventService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://api.hostname.com" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RootNamespace.Api.EventServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我想知道请求是否没有到达 WCF 服务,并且被 IIS 中的另一个处理程序阻止,但它为根 URL 返回不同内容的事实让我怀疑我正在做其他事情这里错了。
更新...
我已经设法通过修改后的 web.config 取得了一些进展:
<behaviors>
<serviceBehaviors>
<behavior name="RootNamespace.Api.EventServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="RootNamespace.Api.EventServiceBehavior"
name="RootNamespace.Api.EventService">
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="WebBehavior"
contract="RootNamespace.Api.IEventService">
</endpoint>
</service>
</services>
这显然与我的第一次尝试有很大不同,但目标保持不变 - 我想使用 Web 浏览器导航到我的服务合同 (IEventService) 的 WebGet 属性中定义的 URL。
使用此 Web 配置,我现在收到我定义的方法的 403 禁止错误,而不是收到 400 错误。对于不存在的方法,我正确地收到“找不到端点”消息。这让我觉得我的东西运行正常,但只是在应用层遇到了某种身份验证问题。
我也觉得我把这件事弄得太复杂了。毕竟,这无需在 Visual Studio Web 服务器中进行任何类型的配置即可工作。
【问题讨论】:
-
IIS网站的实际地址和你配置的baseAddress是否有冲突?