我不斷收到對我想通過REST暴露一個很基本的WCF服務404的時候 - 我試圖將這個URL來訪問它在調試時: http://localhost:62888/Service1.svc/xml/data/testWCF REST 404試圖GET
我可以查看http://localhost:62888/Service1.svc服務信息,但不是http://localhost:62888/Service1.svc/xml
我正在使用.Net 4及其WCF服務應用程序項目。我試着調試與卡西尼和IIS快遞
的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服務庫?
謝謝!這工作(facepalm),我也不得不刪除 ,因爲這不適用於UriTemplate –
2011-12-23 19:21:20