2010-07-20 70 views
0

託管時,我一直在使用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服務器中沒有任何配置。

+0

IIS網站的實際地址與您在配置中的baseAddress之間是否存在衝突? – 2010-07-20 11:02:29

回答

0

我覺得你的問題是這樣的:

  • 如果已經啓用,並在你的配置的httpGetEnabled=true(和你),然後打的基地址(baseAddress="http://api.seetickets.com")服務元數據會呈現出元數據「你有服務」頁面。這是默認的WCF行爲。

  • 你有一個介紹HTML頁 「生活」 在同一個地址 - >你有衝突

你可以做兩件事情,真正做到:

  • 禁用httpGetEnabled在你的服務元數據

或:

  • 將您的介紹頁移至另一個地址,例如http://api.seetickets.com/intro或其他東西(通過在服務方法上設置UriTemplate="....."
+0

感謝您的輸入Marc。我已經用修改後的信息稍微更新了我的問題。我曾嘗試禁用httpGetEnabled,但不幸的是,這似乎並沒有工作。 – Jamie 2010-07-20 13:21:10

相關問題