繁体   English   中英

如何知道 WCF 服务是否使用 protobuf-net?

[英]how to know if a WCF service uses protobuf-net?

我试图让谷歌协议缓冲区序列化与 WCF 服务一起工作。 服务和客户端都启动,对象返回给客户端,但我不确定现在使用什么序列化。 将“behaviorExtensions”中的名称更改为不存在的名称没有任何区别,并且该服务根本没有 protobuf 配置,这就是我怀疑的原因。

下面是客户端的相关配置:

<system.serviceModel>
  <behaviors>
<endpointBehaviors>
        <behavior name="protoEndpointBehavior">
          <!--<protobuf/>-->
         </behavior>
</endpointBehaviors>
   </behaviors>

<bindings>
    <netTcpBinding>
      <binding name="netTcpIoService">
     <reliableSession inactivityTimeout="infinite" enabled="true" />
    </binding>
    </netTcpBinding>
</bindings>
<client>
    <endpoint address="net.tcp://localhost:9001/IoService/IoService"                     binding="netTcpBinding" bindingConfiguration="netTcpIoService"
                contract="IoService.IIoService" name="netTcpIoService" behaviorConfiguration="protoEndpointBehavior">
            <identity>
            <userPrincipalName value="a@b.nl" />
            </identity>
    </endpoint>

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

以及服务上的配置:

<system.serviceModel>
    <behaviors>
    <endpointBehaviors>
        <behavior name="protoEndpointBehavior">
          <!--<protobuf/>-->
        </behavior>
    </endpointBehaviors>
    </behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
        <netTcpBinding>
          <binding name="netTcpIoService">
             <reliableSession inactivityTimeout="infinite" enabled="true" />
            </binding>
        </netTcpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="serviceBehaviour" name="ioService.IoService">
            <endpoint address="IoService" binding="netTcpBinding" bindingConfiguration="netTcpIoService" name="netTcpIoService" contract="ioService.IIoService" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://localhost:9001/IoService" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

服务接口和要序列化的对象:

[ServiceContract(CallbackContract = typeof(IIoServiceCallback)), ProtoBuf.ProtoContract]
public interface IIoService {
    [OperationContract]
    Article GetArticle(string number);
}

    [Serializable]
    [ProtoContract]
    public class Article : EntityBase
    {
        [ProtoMember(1)]
        public string Id;

        [ProtoMember(2)]
        public string Number;

        [ProtoMember(3)]
        public string Description;

        [ProtoMember(4)]
        public string Name;
}

编辑:

在意识到行为不会在客户端和服务器共享并且它们必须在两个点都配置行为之后,我将其添加到服务配置中:

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

然后该服务将无法工作,因为它无法与版本 2.0.0.480 进行程序集,并且必须将其更改为 .668。 然后它又起作用了。 但是我没有看到没有扩展行为的版本的性能提高,所以我仍然怀疑。

我确实添加了

ProtoBuf.Serializer.PrepareSerializer<Article>(); 

服务,但它没有帮助。

仍然不确定如何检查 Article 对象是否通过 protobuf-net.dll 软件序列化。

最后通过让服务使用 .NET 序列化和客户端 protobuf 来解决所有问题。 那么 null 将被返回。 然后使服务也使用 protobuf 序列化并返回有效对象。

这些是正确的配置设置,客户端和服务的结构相同:

 <system.serviceModel>     
    <behaviors>
        <endpointBehaviors>
            <behavior name="protobuf">
                <protobuf />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <client_or_services/service>
        <endpoint address="net.tcp://localhost:9001/Service/Service" 
            binding="netTcpBinding" bindingConfiguration="netTcpService" behaviorConfiguration="protobuf"
            contract="IoService.IIoService" name="netTcpService">
        </endpoint>
    </client_or_services/service>
    <extensions>
          <behaviorExtensions>
            <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.668, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
          </behaviorExtensions>
    </extensions>   
  </system.serviceModel> 

暂无
暂无

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

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