简体   繁体   English

WCF服务中的重载帮助方法

[英]Overload help method in WCF service

for some reason I am asked to see if it possible to override the /help method of a service to return custom data instead. 由于某些原因,我被要求查看是否有可能覆盖服务的/ help方法以返回自定义数据。 Currently I have a calling url like this one 目前,我有一个这样的呼叫网址

http://{myDomain}/CRM/Customers.svc/json/help http:// {myDomain} /CRM/Customers.svc/json/help

Which returns all methods available 哪个返回所有可用的方法

看这里

I tried something like this in my serviceContract, but I can't access to my method, is it possible ? 我在serviceContract中尝试了类似的方法,但是无法访问我的方法,可以吗?

[WebInvoke(Method = "GET", UriTemplate = "/help", RequestFormat = WebMessageFormat.Json, 
                           ResponseFormat = WebMessageFormat.Json)]
void GetInformations();

Thanks 谢谢

By default in web.config help page is enabled in the web http endpoint. 默认情况下,在Web http端点中启用了web.config帮助页面。 To override it you could set as false, then your override method will be triggered. 要覆盖它,可以将其设置为false,然后将触发覆盖方法。

  <webHttpEndpoint>
        <!-- TIP: Enable automatic XML/JSON support -->
        <!-- TIP: Enable service help page -->
        <standardEndpoint automaticFormatSelectionEnabled="true" helpEnabled="false"/>
      </webHttpEndpoint>

Thanks to @Balaji I dig a bit more and was able to make it work in a slightly different way. 感谢@Balaji,我进行了更多的挖掘,并能够使它以略有不同的方式工作。 I applied a custom behaviorConfiguration to my service and in it I disabled the help, see below 我将自定义behaviorConfiguration应用于我的服务,并在其中禁用了帮助,请参见下文

<system.serviceModel>
    <services>
        <service behaviorConfiguration="ServiceBehavior" name="{myDomain}.CRM.Customers">
            <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="JsonBehavior" bindingConfiguration="" contract="{contract}"/>
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
            <behavior name="JsonBehavior">
                <webHttp helpEnabled="false"/>
            </behavior>
       </endpointBehaviors>
    </behaviors>
</system.serviceModel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM