2013-07-14 13 views
7

Gdzie w bloku web.config powinny następować następujące bloki kodu dla usługi WCF REST?Konfigurowanie usług restrykcji wcf w web.config

<endpoint address="" binding="webHttpBinding"contract="Wcf_Test.IMyService"  
behaviorConfiguration="httpEndpointBehavour"> 
<identity> 
<dns value="localhost"/> 
<Identity> 
</endpoint> 

i

<behaviors> <serviceBehaviors> 
<behavior name="httpBehaviour"> <serviceMetadata httpGetEnabled="True"/> 
<serviceDebug includeExceptionDetailInFaults="False"/> 
</behavior></serviceBehaviors> 

i

<endpointBehaviors> 
<behavior name="httpEndpointBehavour"> 
<webHttp /> </behavior> 
</endpointBehaviors> 
+1

użycie WCF redaktor SVC config. – avi

Odpowiedz

24

Aby skonfigurować usługę WCF REST, trzeba parę rzeczy w pliku web.config

1) stwierdzenie, Twoja usługa i jej punkt końcowy:

<services> 
    <service name="SparqlService.SparqlService" behaviorConfiguration="ServiceBehavior"> 
    <endpoint binding="webHttpBinding" contract="SparqlService.ISparqlService" 
       behaviorConfiguration="webHttp"/> 
    </service> 
</services> 

Nazwa usługi będzie [nazwa projektu]. [Nazwa usługi] Konfiguracja zachowania będzie taka sama, jak zachowanie, które zadeklarowałeś w następnym kroku. Powiązanie musi być webHttpBinding, ponieważ chcesz go jako REST. Jeśli chcesz mydło, można zadeklarować jako basicHttpBinding umowy jest [nazwa projektu]. [Nazwa interfejsu] Konfiguracja Zachowanie w końcowym będzie nazwa zadeklarować w następnym kroku

2) deklaruje zachowanie usług (zwykle domyślnie)

<behavior name="ServiceBehavior" > 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 

nazwa zachowanie może być cokolwiek, ale będzie on używany w celu dopasowania BehaviorConfiguration ty zadeklarowane w kroku 1 zostawić resztę

3) zadeklaruje swój końcowy zachowanie

<endpointBehaviors> 
    <behavior name="webHttp"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 

Nazwa zachowania może być dowolna, ale będzie używana do dopasowania zachowania Konfiguracja w punkcie końcowym.

W końcu, to co web.config powinien wyglądać na prosty usługi REST:

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 

    <services> 
     <service name="SparqlService.SparqlService" behaviorConfiguration="ServiceBehavior"> 
     <endpoint binding="webHttpBinding" contract="SparqlService.ISparqlService" 
        behaviorConfiguration="webHttp"/> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 

     <behavior name="ServiceBehavior" > 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 


     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 

     <endpointBehaviors> 
     <behavior name="webHttp"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 

    </behaviors> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 
+3

Ten wpis jest przydatny dla początkujących. Byłoby lepiej, gdyby istniało wyjaśnienie powiązań i ich implikacji. W każdym razie, dzięki. –

+0

Wszystko dla podstawowego powiązania HTTP? – AskMe

1

dla typu spoczynku wykorzystaniem WCFservice

<configuration> 
    <system.serviceModel> 
     <services> 
      <service> 
    <-- 
     "place the first code snippet here " 
     it will contain the endpoint details 
     for WCFrestfulServices it will have 'A' ,'B' and 'C' 
     that is address, binding and contract 
    --> 
      </service> 
     </services> 
     <behaviors> 
     <servicebehaviours> 
    <-- 
     "place the second code snippet" 
     the name of the behavior should be the same to that of the 
     behavior configuration attribute value of service tag 
    --> 
     </servicebehaviours> 
     <endpointBehaviors> 
    <-- 
     "place your third code snippet" 
     the name of the behavior should be the same to that of the 
     behavior configuration attribute value of endpoint tag 
    --> 
     </endpointBehaviors> 
     </behaviors> 
    </system.serviceModel> 
</configuration> 
Powiązane problemy