TL;博士-我有[WebGet(UriTemplate = "/")],但不起作用
我有WCF服务,如下所示:
public interface IUserService
{
// This doesn't work
[OperationContract]
[WebGet(UriTemplate = "/")]
IList<User> GetAllUsers();
/////////////////////////////////////
// Everything below this works
/////////////////////////////////////
[OperationContract]
[WebGet(UriTemplate = "/{id}/")]
User GetUserById(string id);
[OperationContract]
[WebInvoke(UriTemplate = "/", Method = "POST")]
IList<User> AddUser();
[OperationContract]
[WebInvoke(UriTemplate = "/{id}/", Method = "PUT")]
IList<User> UpdateUser(string id, User user);
}以下是端点的配置
<service name="MyCompany.UserService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/api/users/" />
</baseAddresses>
</host>
<endpoint address=""
behaviorConfiguration="WebHttpBehavior"
binding="webHttpBinding"
contract="MyCompany.IUserService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint address="soap"
binding="wsHttpBinding"
contract="MyCompany.IUserService" />
</service>正如您所看到的,我同时提供此服务的REST和SOAP。这个问题只涉及休息。
当我在浏览器中访问http://localhost:80/api/users/ ( WCF术语是GET "/" )时,我得到了描述端点的WCF帮助页面--这个端点对SOAP很有用,但对REST没有多大帮助。但是,如果我还做了什么,它就会像预期的那样工作。如果我POST到这个URL,或者GET /123456,我会得到正常的JSON响应(就像它实际上执行我的服务一样)。
看来WCF正在劫持"/“行动。有没有办法关闭这个WCF的“帮助”行为,以便我可以执行我的操作?任何建议都是非常感谢的。
发布于 2012-06-13 18:17:08
首先,可以使用以下配置选项禁用服务帮助页:
<serviceBehaviors>
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" />
</serviceBehaviors>但是,这将使基址在默认情况下返回服务wsdl。因此,要将其移动,还可以使用以下配置选项:
<serviceBehaviors>
<serviceMetadata httpGetEnabled="true" httpGetUrl="wsdl"/>
</serviceBehaviors>这将将wsdl url移动到your_service_base_address + "wsdl?wsdl“。
https://stackoverflow.com/questions/10806875
复制相似问题