【发布时间】:2015-07-14 00:04:15
【问题描述】:
我的 WCF 服务是自托管的,我使用 WebServiceHost 进行托管,使用以下代码:
WcfGatewayDatas.cs
public WcfGatewayDatas()
{
Uri baseAddress = new Uri("http://localhost:1478/");
this.Host = new WebServiceHost(this, baseAddress);
this.host.open();
}
我的基本界面是这样的(不用担心新的):
IWcfGatewayDatas.cs
[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>
当服务启动时,我尝试使用我的网络浏览器访问 url (http://localhost:1478/GatewayJaguar/Alarms/Last),但我总是遇到相同的错误:不允许使用方法。唯一允许的一个是 post(无论我在我的界面 WebGet 或 WebInvoke 中写什么)。我错过了什么吗?
编辑:即使我的 url 与 WCF 函数不匹配,我也会遇到此错误。
【问题讨论】: