簡體   English   中英

WCF Rest Web服務-IIS中的錯誤請求

[英]WCF Rest Webservice - Bad Request in IIS

我將WCF Rest服務發布到IIS時遇到問題。 VS都可以正常工作,但是通過IIS運行時,我總是收到一個Bad Request。

一些示例代碼,我的服務就這么簡單:

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Admin
{
    [WebGet(UriTemplate = "Field/GetAll")]
    public IList<EntityFields> GetFields() ...

我已將路線添加到我的global.asax中:

RouteTable.Routes.Add(new ServiceRoute("Admin", new WebServiceHostFactory(), typeof(Admin)));

我的web.config看起來像這樣。 我希望這是我做錯事的地方。 請注意,從這里閱讀和MS論壇等,這已經改變了許多次。

<system.web>
  <compilation debug="true" targetFramework="4.0" />
</system.web>

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="UrlRoutingModule" 
       type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </modules>
  <handlers>
    <add name="UrlRoutingHandler"
       preCondition="integratedMode"
       verb="*"
       path="UrlRouting.axd"
       type="System.Web.HttpForbiddenHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </handlers>
</system.webServer>

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <standardEndpoints>
    <webHttpEndpoint>
      <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
    </webHttpEndpoint>
  </standardEndpoints>
</system.serviceModel>

注意它們是否有用:

  • IIS 7.5
  • Windows Server 2008 R2
  • 我正在通過AJAX調用使用JSONP的許多方法。
  • 因為我正在使用JSONP,所以設法使其正常工作的唯一方法是將所有必需的方法轉換為GET,並使用流來調用回調
  • 通過Visual Studio啟動時,一切正常。 我將其托管在IIS中時會出現問題。

任何想法都非常歡迎。

在我看來,這個問題最終與REST和我的配置無關。 我通過將以下內容添加到配置中來啟用WCF Web服務:

<system.diagnostics>
  <sources>
    <source name="System.ServiceModel"
            switchValue="Information, ActivityTracing"
            propagateActivity="true" >
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="myUserTraceSource"
            switchValue="Information, ActivityTracing">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
         initializeData="C:\logs\Error.svclog" />
  </sharedListeners>
</system.diagnostics>

再次點擊我的Web服務以獲取錯誤,然后彈出打開“ SvcTraceViewer.exe”中的跟蹤日志。 這突出了我在數據庫上使用集成安全性的事實。 但是因為我通過瀏覽器和IIS托管站點訪問該服務,所以我在“應用程序池標識”下訪問了數據庫。 這在WCF跟蹤中突出顯示了此錯誤:

System.Data.SqlClient.SqlException: Cannot open database "XYZ" requested by the login. The login failed...

長話短說,我真是個蠢貨...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM