我有一个非常基本的WCF服务,我想在IIS上作为REST式服务运行。这是服务合同。在web.config中添加配置时,WebHttpBinding无法正常工作WCF服务
[ServiceContract]
interface IRestCameraWs
{
[OperationContract]
[WebGet(UriTemplate = "/cameras/{username}",ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
CameraInfo[] GetUserCameras(string username);
[OperationContract]
[WebGet(UriTemplate = "/liveimage/{cameraId}",ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
byte[] GetLiveImage(int cameraId);
//void GetLatestImage(int cameraId, out DateTime timestamp, out byte[] image);
[OperationContract]
[WebGet(UriTemplate = "/latestimage/{cameraId}", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetLatestImageUrl(int cameraId);
}
有一个类实现这个契约StopMotion.Business.WCFService.RestCameraWs
。然后我在我的web项目中添加了一个.svc
文件,并带有以下标记。
<%@ ServiceHost Service="StopMotion.Business.WCFService.RestCameraWsBase"%>
当我导航到这个服务url时,它显示了我的服务主页和一个wsdl定义的链接。但是当我在我的web.config
文件中添加配置以在webHttpBinding
上配置此服务时,我从IIS Express获得以下错误页面。
首先我认为我做错了什么进行配置。后来我删除了配置和只是改变了工厂的SVC文件类似
<%@ ServiceHost Factory="System.ServiceModel.Activation.WebServiceHostFactory" Service="StopMotion.Business.WCFService.RestCameraWsBase"%>
WebServiceHostFactory
据说用默认webHttpBinding
,我们不需要,除非我们需要更多的东西出来它添加这配置。但更改工厂也导致在IIS Express上出现相同的错误页面。
任何想法这里发生了什么?
谢谢jbl。我还没有达到那么远。但迟早我会需要这一个。 +1,非常感谢您的帮助。 – 2012-04-13 08:03:44