託管時,我一直在使用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