I've created the following RESTful WCF service, which works just fine when running it in VS.
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/sales/start={start}&end={end}")]
List<Sales> GetSalesByDate(string start, string end);
However, when deploying this to my test server (running Win2K3 and IIS6) I received the following server error:
Operation 'GetSalesByDate' in contract 'ISalesService' uses GET, but also has body parameter 'start'. GET operations cannot have a body. Either make the parameter 'start' a UriTemplate parameter, or switch from WebGetAttribute to WebInvokeAttribute.
Obviously I have already made 'start' a UriParameter. So can anyone tell me why an exception is being thrown?
EDIT: For reference, here is my configuration file:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Services.SalesService">
<endpoint behaviorConfiguration="webBehavior"
binding="webHttpBinding"
contract="Services.ISalesService"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
-
I bet it is that the dev machine has SP1 and the server does not.
http://blogs.msdn.com/endpoint/archive/2008/08/22/rest-in-wcf-part-ix-controlling-the-uri.aspx
Kevin Babcock : No, SP1 is installed. That was the first thing I checked. -
It turns out
/sales/start={start}&end={end}is not a valid Uri (duh!). After a little trial and error I finally figured this out. Tweaking the UriTemplate with a '?' solved the problem.[OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/sales/?start={start}&end={end}")] List<Sales> GetSalesByDate(string start, string end);Thanks for your help!
Brian : I don't understand why it worked on the dev box, but not on the server. But I'm glad you are unblocked!Kevin Babcock : Me either. It works just fine in VS with the incorrect Uri. Weird, I know...
0 comments:
Post a Comment