2017-04-19 4 views
1

以前はWCFで作業しました。しかし、私はプロトコルバッファで非常に新しいです。私はその利点と使い方を調べました。基本的に私は、既存の 'WCFライブラリ'にプロトコルバッファを接続したいと思っています。では、既存の「app.config」ファイルで、プロトコルバッファの導入や開始を変更する必要がありますか? 私の既存サービスの設定ファイルは以下の通りです。プロトコルバッファを使用したWCFサービス、設定ファイルの外観

<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> 

助けてください!ここで おかげ

答えて

1

ちょうどsystem.serviceModelセクションを変更...私はあまりにも、クライアント側の設定ファイルを変更し、私はこれに沿って

<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> 


サービス側のための設定で行った変更であります

<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> 

また、WCFデータ共同体のためのprotobufシリアル化を有効にするにはntractsは、まずあなたは

  • [追加.. [のDataContract]属性と [のServiceContract]属性を必要とするすべてのDTO(データ転送 オブジェクト)に[ProtoContract]属性を追加

    1. に必要ProtoMember]属性を[DataMember]属性の を必要とするすべてのDTOデータフィールドに割り当てます。

      [ProtoContract]
      が [のServiceContract]

    なく、少なくとも最後に追加

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

    変更service-ためIServiceため

    が変化だけでサービス契約上Protocontract属性を追加します

    using ProtoBuf 
    

    参照さ...

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

  • +1

    リンクが死んだ場合でも、あなたの答えはまだ便利になるように、あなたの答えに十分な情報を入れてください。現在のところ、これは削除の候補であるリンクオンリーの回答です。 – DeanOC

    +0

    私に通知してくれてありがとう...私は実装した実際のソリューションを共有します。 – Lina

    +0

    それははるかに良いです。情報を答えに入れる時間をとってくれてありがとう。 – DeanOC

    関連する問題