托管时,我一直在使用C#和Visual Studio 2008WCF应用程序返回400错误的请求在IIS7
写一个WCF Web服务当我运行它使用内置的开发Web服务器,我可以查看结果通过浏览到服务合同的[WebGet(UriTemplate =“..”)]属性中指定的URL来访问各种方法。
具体来说,我有一个匹配“/”URL的方法,并返回一个纯HTML文件。
但是,当我部署到在Windows Server 2008上运行的IIS时,此方法将返回标准的“您已创建服务”页面。
如果我尝试执行我的任何其他方法,使用我指定的URI的模板,例如:
api.hostname.com/Service.svc/method/param
服务器返回400错误的请求。
我住的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浏览器导航到m的WebGet属性中定义的URL y服务合同(IEventService)。
使用这个网络配置,而不是得到400错误,我现在收到了我定义的方法403禁止错误。对于不存在的方法,我会正确接收“未找到端点”消息。这使我认为我的东西正常运行,但在应用程序层只是遭受某种身份验证问题。
我也越来越觉得我太复杂了。毕竟,这在Visual Studio Web服务器中没有任何配置。
IIS网站的实际地址与您在配置中的baseAddress之间是否存在冲突? – 2010-07-20 11:02:29