【发布时间】:2011-07-25 11:12:42
【问题描述】:
谁能告诉我为什么这个 REST 服务不起作用?
namespace WCFRestExample
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class HelloWorld : IHelloWorld
{
[WebGet(UriTemplate="/", ResponseFormat=WebMessageFormat.Xml)]
public string GetData()
{
return "HIIII";
}
}
}
namespace WCFRestExample
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IHelloWorld
{
[OperationContract]
string GetData();
}
}
这是我的 web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
我能够浏览服务 .svc 并且我可以正确获取页面,但是当我浏览时:
http://localhost:60503/HelloWorld.svc/GetData
我得到一个 404 页面。谁能告诉我发生了什么,我在哪里可以找到 WCF REST 的教程?这是可以创建的最简单的服务,但对我也不起作用。
提前致谢:)
【问题讨论】:
-
是否有用于 REST 的 wsdl?不,至少在默认情况下,据我所知。这显然不是高度定制的解决方案:)
-
@Tom Squires:WSDL 用于 SOAP 服务而不是基于 Http 的 REST 服务。看来你也是新手;)
-
显示 svc 文件内容,可能是 ServiceFactory 配置错误。
-
@Int3:
-
这还不够,还需要提供servicefactory