[英]Dead simple WCF - 405 Method not allowed
据我所知, 我已经模仿了此职位和该职位的公认解决方案 。 除非我是盲人(我希望现在是这样),否则我将为我非常简单的WCF服务提供一尘不染的app.config
:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RESTBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="Vert.Host.VertService.RSVPService">
<endpoint
address="/RSVP"
binding="webHttpBinding"
contract="Vert.Host.VertService.IRSVP"
behaviorConfiguration="RESTBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Vert" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
以下是相应的服务合同和实施:
namespace Vert.Host.VertService
{
[ServiceContract]
public interface IRSVP
{
[OperationContract]
bool Attending();
[OperationContract]
bool NotAttending();
}
public class RSVPService : IRSVP
{
public bool Attending()
return true;
public bool NotAttending()
return true;
}
}
我通过控制台应用程序托管所有内容:
class Program
{
public static void Main()
{
// Create a ServiceHost
using (ServiceHost serviceHost = new ServiceHost(typeof(RSVPService)))
{
serviceHost.Open();
// The service can now be accessed.
Console.ReadLine();
}
}
}
我要做的只是站起这个微小的服务,但是我无法使用http://localhost:8080/Vert/RSVP/Attending
此端点。 我仍然收到405 Method not allowed
作为响应。我使用的是Visual Studio Community 2015,IIS10,目标是.NET 4.6
我从建议中尝试过的事情:
我想念什么?
老实说,不确定这是否会有所作为,但是我的公司与服务行为有联系。 为您的服务行为命名:
<serviceBehaviors>
<behavior name="ServiceBehavior">
然后将其链接到您的服务:
<service name="Vert.Host.VertService.RSVPService" behaviorConfiguration="ServiceBehavior">
确保使用[WebGet]
属性(参考System.ServiceModel.Web.dll
)修饰服务方法。
即从更改服务
public class RSVPService : IRSVP
{
public bool Attending()
return true;
public bool NotAttending()
return true;
}
至
public class RSVPService : IRSVP
{
[WebGet]
public bool Attending()
return true;
[WebGet]
public bool NotAttending()
return true;
}
解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.