我已經通過堆棧交換進行了搜索,雖然有很多類似的問題,但我一直無法解決這個問題。 我需要在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>
非常感謝您的幫助!
此外,當我嘗試通過客戶端應用程序訪問此問題時,我得到以下異常無法找到在ServiceModel客戶端配置部分中引用合同'MvcWebRole1.ItestAPI'的默認端點元素。這可能是因爲沒有找到適用於您的應用程序的配置文件,或者因爲在客戶端元素中找不到匹配此合同的端點元素。 – Gotts