据我所知我已模仿this post和this post 的已接受的解决方案。除非我是盲目的(我希望我在这一点上),对于我非常简单的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
作为回应。我正在使用针对.NET 4.6的Visual Studio Community 2015,IIS10
我从建议中尝试过的事情:
我缺少什么?
答案 0 :(得分:0)
老实说,不确定这是否会产生影响,但我的服务行为有链接。为您的服务行为命名:
<serviceBehaviors>
<behavior name="ServiceBehavior">
然后将其链接到您的服务:
<service name="Vert.Host.VertService.RSVPService" behaviorConfiguration="ServiceBehavior">
答案 1 :(得分:0)
请务必使用[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;
}
解决问题。