2016-12-07 19 views
0

出於某種原因,我被問到是否可以重寫服務的/ help方法來返回自定義數據。目前,我有這樣一個WCF服務中的重載幫助方法

HTTP主叫網址:// {} myDomain的/CRM/Customers.svc/json/help

返回一個可用的

see here

所有方法

我在我的serviceContract中嘗試過這樣的事情,但我無法訪問我的方法,這有可能嗎?

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

感謝

+0

如果簽名是公開的,而不是私人? –

+0

爲的ServiceContract接口是公開的,所以沒有知名度的麻煩,我認爲 –

回答

0

感謝@Balaji我挖掘了一點,並能夠以稍微不同的方式工作。 我申請一個自定義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> 
+0

我在頁面中使用了單一配置。對於您的要求,請參閱文檔https://msdn.microsoft.com/en-us/library/ee230442(v=vs.110).aspx,就像您一樣。 –

+0

再次感謝您的幫助! –

1

默認情況下,在web.config中幫助頁面在Web HTTP端點啓用。要覆蓋它,你可以設置爲false,那麼你的覆蓋方法將被觸發。

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

您的解決方案似乎是我需要什麼,我在system.serviceModel節點添加了這個在web.config 但它不會改變出現幫助頁面,我失去的東西嗎? Bonus point:我在web.config中配置了多個服務,是否可以將此修改僅應用於我需要的服務? –