[英]WCF rest webservice in Azure Web Role - 404 error
I have searched through stack exchange and while there are many similar questions to this I have not been able to sole this problem. 我已经通过堆栈交换进行了搜索,尽管有很多与此类似的问题,但我无法解决这个问题。 I need to run a WCF web service on an Azure webrole (as I am running regular web pages also) and not a Azure Web Service role.
我需要在Azure webrole上运行WCF Web服务(因为我也在运行常规网页),而不是Azure Web Service角色。 I have setup a WCF service and defined the endpoints in the web.config but I am not able to connect to the endpoint through my browser or through a client.
我已经设置了WCF服务并在web.config中定义了端点,但是我无法通过浏览器或客户端连接到端点。 Below is the code - would really appreciate it if someone can advise as to what might be going wrong.
以下是代码-如果有人可以提供建议以解决问题,将不胜感激。
Given the code below I would assume that the following would work in the browser 给定下面的代码,我假设以下内容将在浏览器中运行
http://127.0.0.1:81/testAPI.svc/store/
but I get a 404 on that If i just specify 但是我得到一个404如果我只是指定
http://127.0.0.1:81/testAPI.svc
I get the page telling me that I have a web service. 我得到的页面告诉我我有一个Web服务。
ItestAPI.cs 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 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; }
}
}
and finally the service model in web.config 最后是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>
Thanks very much for ANY help here! 非常感谢您的任何帮助!
I discovered the following: If I setup a WCFServiceWebRole using the above classes and config then it all worked perfectly. 我发现了以下内容:如果我使用上述类和配置设置了WCFServiceWebRole,那么它们都可以完美运行。 It was only an issue when trying to run the above in an MCVWebRole.
尝试在MCVWebRole中运行上述命令时,这只是一个问题。
After playing around with MVCWebRole web.config I finally got it to work. 在玩了MVCWebRole web.config之后,我终于使它工作了。 As you can probably tell I am new to .NET but removing the following from my MVWWebRole solved the problem.
您可能会说,我是.NET的新手,但从MVWWebRole中删除以下内容可以解决此问题。 I am sure there will be consequences to this but at least I have isolated the issue.
我相信这将带来后果,但至少我已经隔离了这个问题。
Just thought I would share in case it helps anyone else out. 只是以为我会分享,以防其他人受益。
This is what I removed 这是我删除的
<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>
If someone can tell me exacctly what is causing the problem it would be helpful. 如果有人可以准确地告诉我是什么原因引起的,那将是有帮助的。 Thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.