Reputation: 17794
I have a very basic WCF service that I want to run on IIS as a RESTful service. Here is the service contract.
[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);
}
There is a class which implements this contract called StopMotion.Business.WCFService.RestCameraWs
. Then I added an .svc
file in my web project with following markup.
<%@ ServiceHost Service="StopMotion.Business.WCFService.RestCameraWsBase"%>
When I navigate to this service url, it shows me service home page and a link to wsdl definition. But when I add configuration in my web.config
file to configure this service on webHttpBinding
I get following error page from IIS express.
First I thought I am doing something wrong with configuration. Later I deleted the configuration and just changed the factory in svc file like
<%@ ServiceHost Factory="System.ServiceModel.Activation.WebServiceHostFactory" Service="StopMotion.Business.WCFService.RestCameraWsBase"%>
WebServiceHostFactory
is said to use webHttpBinding
by default and we don't need to add this in configuration unless we need something more out of it. But changing factory also resulted in the same error page on IIS Express.
Any ideas what's going on here?
Upvotes: 0
Views: 1399
Reputation: 17794
The problem was with my method signatures. we can only have parameters of type string
which are included in UriTemplate
whereas some of methods were accepting parameters of type int
like following.
[OperationContract]
[WebGet(UriTemplate = "/latestimage/{cameraId}",ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetLatestImageUrl(int cameraId);
When i debugged it on vs dev server, it laid the error on line for me but it seems that observing the error is more difficult in IIS Express even in the dev environment.
Upvotes: 0
Reputation: 15413
Looking in my configs, I remember that I had to declare the end point in the web.config and enableWebScript in the behavior. Part of the result looks somewhat like :
<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>
Hope this can be helpful
Upvotes: 1