我已经通过堆栈交换进行了搜索,虽然有很多类似的问题,但我一直无法解决这个问题。 我需要在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