2017-04-19 2 views
1

J'ai déjà travaillé sur WCF. Mais je suis très nouveau dans les tampons de protocole. Je suis allé à travers ses avantages et comment l'utiliser. Fondamentalement, je veux brancher les tampons de protocole dans ma «bibliothèque WCF» existante. Alors, quels changements dois-je faire dans mon fichier 'app.config' existant pour introduire ou commencer à travailler avec des tampons de protocole? Mon fichier de configuration de service existant est le suivant.Service WCF avec tampon de protocole, à quoi ressemblera le fichier de configuration

<configuration> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    <add key="ClientSettingsProvider.ServiceUri" value="" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" /> 
    <membership defaultProvider="XYZProvider"> 
     <providers> 
     <add name="XYZshipProvider" type="System.Web.ClientServices.Providers.XYZProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf35678563123ad364e35" serviceUri="" /> 
     </providers> 
    </membership> 
    <roleManager defaultProvider="ClientRoleProvider" enabled="true"> 
     <providers> 
     <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856564ad364e35" serviceUri="" cacheTimeout="86400" /> 
     </providers> 
    </roleManager> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <services> 
     <service name="wcfServiceXYZApplication.Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/Design_Time_Addresses/XYZApplication/Service1/" /> 
      </baseAddresses> 
     </host> 
     <!-- Service Endpoints --> 
     <!-- Unless fully qualified, address is relative to base address supplied above --> 
     <endpoint address="" binding="basicHttpBinding" contract="XYZApplication.IService1" bindingConfiguration="basicHttp"> 
      <!-- 
       Upon deployment, the following identity element should be removed or replaced to reflect the 
       identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
       automatically. 
      --> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <!-- Metadata Endpoints --> 
     <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
     <!-- This endpoint does not use a secure binding and should be secured or removed before deployment --> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, 
      set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="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> 
    </behaviors> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="basicHttp" maxReceivedMessageSize="100000" maxBufferSize="100000" maxBufferPoolSize="100000"/> 
    </basicHttpBinding> 
    </bindings> 
    </system.serviceModel> 

</configuration> 

Aidez-nous! Merci

Répondre

1

Voici les modifications que j'ai fait dans la configuration pour le côté service

<configuration> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    <add key="ClientSettingsProvider.ServiceUri" value="" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" /> 
    <membership defaultProvider="XYZProvider"> 
     <providers> 
     <add name="XYZshipProvider" type="System.Web.ClientServices.Providers.XYZProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf35678563123ad364e35" serviceUri="" /> 
     </providers> 
    </membership> 
    <roleManager defaultProvider="ClientRoleProvider" enabled="true"> 
     <providers> 
     <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856564ad364e35" serviceUri="" cacheTimeout="86400" /> 
     </providers> 
    </roleManager> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
<behaviors> 
    <endpointBehaviors> 
    <behavior name="protoEndpointBehavior"> 
     <protobuf/> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<bindings> 
    <netNamedPipeBinding> 
    <binding name="namedPipeBinding" receiveTimeout="00:10:00" sendTimeout="0:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" /> 
    </netNamedPipeBinding> 
</bindings> 

<services> 
    <service name="WcfProtobufService.SimpleService"> 
    <endpoint binding="netNamedPipeBinding" bindingConfiguration="namedPipeBinding" contract="WcfProtobufService.ISimpleService" behaviorConfiguration="protoEndpointBehavior"/> 
    <endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="net.pipe://localhost/console/SimpleService.svc"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 

<extensions> 
    <behaviorExtensions> 
    <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.668, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/> 
    </behaviorExtensions> 
</extensions> 


avec ce que j'ai changé le fichier de configuration côté client aussi ... Il suffit de modifier l'article system.serviceModel comme suit

<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="protoEndpointBehavior"> 
      <protobuf/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <bindings> 
     <netNamedPipeBinding> 
     <binding name="NetNamedPipeBinding_ISimpleService" receiveTimeout="00:10:00" sendTimeout="0:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" /> 
     </netNamedPipeBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.pipe://localhost/console/SimpleService.svc" 
      binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_ISimpleService" 
      contract="SimpleProxy.ISimpleService" name="NetNamedPipeBinding_ISimpleService" behaviorConfiguration="protoEndpointBehavior"> 
     </endpoint> 
    </client> 

    <extensions> 
     <behaviorExtensions> 
     <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.668, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/> 
     </behaviorExtensions> 
    </extensions> 
    </system.serviceModel> 

Également pour activer la sérialisation protobuf pour votre WCF Data Co ntrats, vous devez d'abord

  1. ajouter le [ProtoContract] attribut à chaque DTO (transfert de données Object) qui a besoin de la [DataContract] attribut et la [ServiceContract] attribut ..
  2. ajouter le [ ProtoMember] attribue à chaque champ de données DTO qui a besoin de l'attribut [DataMember].

    changements pour IService

    [ProtoMember(2)] 
        [DataMember(Order = 0)] 
        public string Name { get; set; } 
    

    changements pour service- il suffit d'ajouter l'attribut Protocontract sur le contrat de service

    [ProtoContract]
    [ServiceContract]

Last but not least ajouter

using ProtoBuf 

Référé ...

https://whinery.wordpress.com/2014/10/28/wcf-with-protobuf-serialization/

+1

S'il vous plaît mettre suffisamment d'informations dans votre réponse afin que, même si le lien meurt, votre réponse est toujours utile. Actuellement, il s'agit d'une réponse de type lien uniquement qui peut être supprimée. – DeanOC

+0

Merci de m'avoir informé ... Je partagerai la solution actuelle que j'ai implémentée. – Lina

+0

C'est beaucoup mieux. Merci d'avoir pris le temps de mettre l'info dans la réponse. – DeanOC