为什么此WCF服务无法识别UriTemplate参数?

前端之家收集整理的这篇文章主要介绍了为什么此WCF服务无法识别UriTemplate参数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了以下RESTful WCF服务,在VS中运行它时工作得很好.
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,UriTemplate = "/sales/start={start}&end={end}")]
List<Sales> GetSalesByDate(string start,string end);

但是,当将其部署到我的测试服务器(运行Win2K3和IIS6)时,我收到以下服务器错误

合同’ISalesService’中的’GetSalesByDate’操作使用GET,但也有body参数’start’. GET操作不能有一个正文.将参数’start’设为UriTemplate参数,或从WebGetAttribute切换到WebInvokeAttribute.

显然我已经’开始’了一个UriParameter.所以有人能告诉我为什么会抛出异常吗?

编辑:
作为参考,这是我的配置文件

<?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>

解决方法

事实证明/ sales / start = {start}& end = {end}不是有效的Uri(呃!).经过一番试验和错误后,我终于想通了.使用’?’调整UriTemplate解决了这个问题.
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,UriTemplate = "/sales/?start={start}&end={end}")]
List<Sales> GetSalesByDate(string start,string end);

谢谢你的帮助!

原文链接:https://www.f2er.com/html/226542.html

猜你在找的HTML相关文章