2013-02-01 145 views
0

我已經通過堆棧交換進行了搜索,雖然有很多類似的問題,但我一直無法解決這個問題。 我需要在Azure webrole上運行WCF Web服務(因爲我還運行常規Web頁面),而不是Azure Web服務角色。 我已經設置了一個WCF服務並在web.config中定義了端點,但我無法通過我的瀏覽器或通過客戶端連接到端點。 下面是代碼 - 如果有人可以建議可能會出錯的地方,會非常感激。WCF休息在Azure Web角色的web服務 - 404錯誤

考慮下面的代碼,我會承擔下列瀏覽器

http://127.0.0.1:81/testAPI.svc/store/ 

的工作,但我對 得到一個404,如果我只是指定

http://127.0.0.1:81/testAPI.svc 

我得到的頁面告訴我有一個網絡服務。

ItestAPI.cs

namespace MvcWebRole1 
{ 

    [ServiceContract] 
    public interface ItestAPI 
    { 


     [OperationContract] 
     [WebGet(UriTemplate = "store", 
     RequestFormat = WebMessageFormat.Json, 
     ResponseFormat = WebMessageFormat.Json, 
     BodyStyle = WebMessageBodyStyle.Bare)] 
     List<Financials> GetStoreActuals(); 
    } 
} 

testAPI.svc

namespace MvcWebRole1 
{ 

    public class testAPI : ItestAPI 
    { 
      public List<Financials> GetStoreActuals() 
      { 
       return GetActuals(); 

      } 

      private List<Financials> GetActuals() 
      { 

       List<Financials> Actuals = new List<Financials> 
       { 
        new Financials 
        { 
        Store = "Store1", Profit = "10000000", Sales = "2000000" 
        }, 
        new Financials 
        { 
        Store = "Store2", Profit = "20000000", Sales = "30000" 
        }, 
        new Financials 
        { 
        Store = "Store3", Profit = "30000000", Sales = "4000000" 
        }, 
        new Financials 
        { 
        Store = "Store4", Profit = "4000000", Sales = "500000" 
        }, 

       }; 
       return Actuals; 
      } 

    } 

    [DataContract] 
    public class Financials 
    { 
     [DataMember] 
     public string Store { get; set; } 
     [DataMember] 
     public string Sales { get; set; } 
     [DataMember] 
     public string Profit { get; set; } 


    } 
} 

終於在web.config中的服務模式

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="servicebehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="restbehavior"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <services> 
     <service name ="MvcWebRole1.testAPI" behaviorConfiguration ="servicebehavior" > 
     <endpoint name ="RESTEndPoint" 
     contract ="MvcWebRole1.ItestAPI" 
     binding ="webHttpBinding" 
     address ="" 
     behaviorConfiguration ="restbehavior"/> 
     </service> 
    </services> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

非常感謝您的幫助!

+0

此外,當我嘗試通過客戶端應用程序訪問此問題時,我得到以下異常無法找到在ServiceModel客戶端配置部分中引用合同'MvcWebRole1.ItestAPI'的默認端點元素。這可能是因爲沒有找到適用於您的應用程序的配置文件,或者因爲在客戶端元素中找不到匹配此合同的端點元素。 – Gotts

回答

0

我發現了以下內容: 如果我使用上面的類和配置設置WCFServiceWebRole,那麼它一切都很完美。試圖在MCVWebRole中運行上述內容只是一個問題。

玩過MVCWebRole web.config後,我終於得到它的工作。正如你可能會告訴我新來的.NET,但從我的MVWWebRole刪除以下解決了這個問題。我肯定會有這樣的後果,但至少我已經把這個問題隔離了。

只是想我會分享以防別人幫助其他人。

這是我刪除

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
    </system.webServer> 

如果有人能告訴我exacctly是什麼原因造成的問題,這將是有益的。 謝謝