C# 自托管WCF(Rest)只允许POST方法

C# 自托管WCF(Rest)只允许POST方法,c#,wcf,http,hosting,C#,Wcf,Http,Hosting,我的WCF服务是自托管的,我使用WebServiceHost使用以下代码进行托管: WcfGatewayDatas.cs public WcfGatewayDatas() { Uri baseAddress = new Uri("http://localhost:1478/"); this.Host = new WebServiceHost(this, baseAddress); this.host.open(); } [ServiceContract]

我的WCF服务是自托管的,我使用
WebServiceHost
使用以下代码进行托管:

WcfGatewayDatas.cs

 public WcfGatewayDatas()
 {
     Uri baseAddress = new Uri("http://localhost:1478/");
     this.Host = new WebServiceHost(this, baseAddress);
     this.host.open();
 }
 [ServiceContract]
        public interface IWcfGatewayDatas : IExposeDatas
        {
            [WebGet(/*Method="GET", */UriTemplate = "Alarms/Last")]
            [OperationContract]
            new JaguarEvitech.AgentService.SpyAlarm GetLastAlarm();
        }
我的基本界面如下所示(不用担心新界面):

IWcfGatewayDatas.cs

 public WcfGatewayDatas()
 {
     Uri baseAddress = new Uri("http://localhost:1478/");
     this.Host = new WebServiceHost(this, baseAddress);
     this.host.open();
 }
 [ServiceContract]
        public interface IWcfGatewayDatas : IExposeDatas
        {
            [WebGet(/*Method="GET", */UriTemplate = "Alarms/Last")]
            [OperationContract]
            new JaguarEvitech.AgentService.SpyAlarm GetLastAlarm();
        }
和我的配置文件:

<system.serviceModel>
   <behaviors>
      <endpointBehaviors>
        <behavior name="Wcf">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="WcfBinding"/>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="MilestonePlugin.Background.ExposeDatas.WcfGatewayDatas">
        <endpoint behaviorConfiguration="Wcf" binding="webHttpBinding" contract="MilestonePlugin.Background.ExposeDatas.IWcfGatewayDatas" address="GatewayJaguar"></endpoint>
      </service>
    </services>
  </system.serviceModel>

当服务启动时,我尝试使用我的web浏览器转到url(),我总是遇到相同的错误:方法不允许。唯一允许的是post(无论我在接口WebGet或WebInvoke中写什么)。我错过什么了吗


编辑:即使我的url与WCF函数不匹配,也会出现此错误。

WCF默认仅使用HTTP Post。此链接说明如何选择使用HTTP Get

确定我发现了问题。问题是错误的url请求。我想请求,但我的节目正在收听。我更改了我的uri,现在可以使用了。

我已经将WebGet设置为我的函数,以便执行GET请求。我已经将WebGetAttribute添加到我的函数中。您可以尝试[WebGet(UriTemplate=“/Alarms/Last”)],其中在报警之前有一个“/”