【发布时间】:2012-01-27 00:21:50
【问题描述】:
我在一个非常基本的 WCF 服务上不断收到 404,我想通过 REST 公开该服务 - 我试图在调试时通过访问此 URL 来访问它: http://localhost:62888/Service1.svc/xml/data/test
我可以在http://localhost:62888/Service1.svc查看服务信息,但不能在http://localhost:62888/Service1.svc/xml查看服务信息
我正在使用 .Net 4 及其 WCF 服务应用程序项目。我尝试使用 Cassini 和 IIS Express 进行调试
Web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Service1">
<!-- address is relative-->
<endpoint address="xml" binding="webHttpBinding" behaviorConfiguration="webHttp" contract="IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp /> <!-- enables RESTful in conjunction with webHttpBinging -->
<enableWebScript /> <!-- allows ajax communication -->
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
IService.cs
using System.ServiceModel;
using System.ServiceModel.Web;
namespace CI.WcfRestTest
{
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "/data/{id}")]
string GetData(string id);
}
}
Service1.svc.cs
namespace CI.WcfRestTest
{
public class Service1 : IService1
{
public string GetData(string id)
{
return string.Format("You entered: {0}", id);
}
}
}
我已经阅读了很多关于这个主题的文章,包括这篇 REST / SOAP endpoints for a WCF service 。也许卡西尼或我的机器配置中有什么东西搞砸了?我已经阅读了有关 Windows Vista 的问题,但我使用的是 Windows 7 Pro。也许它与 WCF 服务应用程序而不是 WCF 服务库有关?
【问题讨论】: