C# 尝试获取时WCF REST 404
我一直在一个非常基本的WCF服务上获得404,我想通过REST公开该服务-我试图在调试时通过访问以下URL来访问它: 我可以在查看服务信息,但不能在 我正在使用.NET4及其一个WCF服务应用程序项目。我试着用Cassini和IIS Express进行调试 Web.ConfigC# 尝试获取时WCF REST 404,c#,.net,wcf,rest,wcf-rest,C#,.net,Wcf,Rest,Wcf Rest,我一直在一个非常基本的WCF服务上获得404,我想通过REST公开该服务-我试图在调试时通过访问以下URL来访问它: 我可以在查看服务信息,但不能在 我正在使用.NET4及其一个WCF服务应用程序项目。我试着用Cassini和IIS Express进行调试 Web.Config <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targ
<?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>
Service1.svc.cs
using System.ServiceModel;
using System.ServiceModel.Web;
namespace CI.WcfRestTest
{
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "/data/{id}")]
string GetData(string id);
}
}
namespace CI.WcfRestTest
{
public class Service1 : IService1
{
public string GetData(string id)
{
return string.Format("You entered: {0}", id);
}
}
}
我读了很多关于这个主题的文章,包括这篇。也许卡西尼号或我的机器配置中有什么东西把事情搞砸了?我读过有关Windows Vista的问题,但我使用的是Windows 7 Pro。也许它与WCF服务应用程序有关,而不是与WCF服务库有关?这可能很简单,就像配置中有错误的服务名称一样 目前,您有:
<services>
<service name="Service1">
但是:这需要是完全限定的服务名称-包括任何名称空间
因此,请尝试以下方法:
<services>
<service name="CI.WcfRestTest.Service1">
<!-- address is relative-->
<endpoint address="xml"
binding="webHttpBinding" behaviorConfiguration="webHttp"
contract="CI.WcfRestTest.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
只需将Service1
替换为CI.WcfRestTest.Service1
(合同也是如此)。这能解决你的问题吗???谢谢!这是有效的(facepalm),我还必须删除,因为这不适用于Uri模板