2012-04-13 32 views
0

我有一个非常基本的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获得以下错误页面。

enter image description here

首先我认为我做错了什么进行配置。后来我删除了配置和只是改变了工厂的SVC文件类似

<%@ ServiceHost Factory="System.ServiceModel.Activation.WebServiceHostFactory" Service="StopMotion.Business.WCFService.RestCameraWsBase"%> 

WebServiceHostFactory据说用默认webHttpBinding,我们不需要,除非我们需要更多的东西出来它添加这配置。但更改工厂也导致在IIS Express上出现相同的错误页面。

任何想法这里发生了什么?

回答

1

寻找我的配置,我记得我不得不在web.config中声明终结点,并在行为中启用WebScript。结果的一部分看起来有点像:

<endpoint address="json" binding="webHttpBinding" contract="svcservice.svc.IAuthsvc" bindingConfiguration="bc.svcservice.svc.AuthsvcJSON" behaviorConfiguration="epb.svcservice.svc.AuthsvcJSON"/>  
    . 
    . 
    . 
    . 
    <behavior name="epb.svcservice.svc.AuthsvcJSON"> 
     <enableWebScript/> 
    </behavior> 

希望这可以帮助

+0

谢谢jbl。我还没有达到那么远。但迟早我会需要这一个。 +1,非常感谢您的帮助。 – 2012-04-13 08:03:44

0

的问题是我的方法签名。我们只能有string类型的参数,这些参数包含在UriTemplate中,而其中一些方法正在接受int类型的参数,如下所示。

[OperationContract] 
     [WebGet(UriTemplate = "/latestimage/{cameraId}",ResponseFormat = WebMessageFormat.Xml, 
      BodyStyle = WebMessageBodyStyle.Wrapped)] 
     string GetLatestImageUrl(int cameraId); 

当我调试它VS开发服务器,它放在线上的错误给我,但似乎观测误差甚至在开发环境是IIS Express的困难。