WebInvoke发布错误:不允许的方法

时间:2015-02-19 10:22:01

标签: wcf wcf-data-services

我使用简单实体创建了一个WCF数据服务,如下所示。

namespace DataService
{
using System;
using System.Collections.Generic;

public partial class MemoryPackageData
{
    public long c1 { get; set; }
    public long c2 { get; set; }
    public long c3 { get; set; }
    public long c4 { get; set; }
}
}

namespace DataService
{
    public class WCFDataService : DataService<DBEntities>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            config.SetEntitySetAccessRule("MemoryPackageDatas", EntitySetRights.All);
            config.SetServiceOperationAccessRule("InsertEntityData", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }

        //[WebInvoke(UriTemplate = "InsertEntityData/?package_id={package_id}&package_size={package_size}")]
        [WebInvoke(UriTemplate = "InsertEntityData?package_id={package_id}")]
        public void InsertEntityData(Int64 package_id, Int64 package_Size = 10)
        {
// some stuff
}

现在,当我在firefox中运行此服务并传递一个URL中必需的参数时。

enter image description here

我尝试了很多不同的方法来调用此方法。但不确定如何处理这些参数列表。

方法是将数据插入表格。

任何人都可以在这里指导我吗?

谢谢,

塔尔。

2 个答案:

答案 0 :(得分:0)

默认情况下,WebInvoke会考虑Method =“POST”。 因此,您可以使用WebGet属性或指定Method =“GET”

答案 1 :(得分:0)

在浏览器中,默认方法为&#34; Get&#34;。这就是服务将返回405的原因。 您可以使用Fiddler使用&#34; Post&#34;撰写请求。并尝试。