简体   繁体   English

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

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

Im trying to get google protocol buffer serialization to work with a WCF service.我试图让谷歌协议缓冲区序列化与 WCF 服务一起工作。 The service and client do start both and objects are returned to the client but I'm not sure what serialization is used now.服务和客户端都启动,对象返回给客户端,但我不确定现在使用什么序列化。 Changing the names in "behaviorExtensions" to something non-existing makes no difference, and the service has no protobuf configuration at all, thats why I'm doubting.将“behaviorExtensions”中的名称更改为不存在的名称没有任何区别,并且该服务根本没有 protobuf 配置,这就是我怀疑的原因。

Here's the relevant configuration on the client side:下面是客户端的相关配置:

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

and the configuration on the service:以及服务上的配置:

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

The service interface and the object to be serialized:服务接口和要序列化的对象:

[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;
}

Edit:编辑:

After realizing that behaviours are not shared at the client and server and that they must have the behaviour configured at both points I added this to the service config:在意识到行为不会在客户端和服务器共享并且它们必须在两个点都配置行为之后,我将其添加到服务配置中:

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

Then the service would not work because it could not the assembly with version 2.0.0.480 and it had to be changed to .668.然后该服务将无法工作,因为它无法与版本 2.0.0.480 进行程序集,并且必须将其更改为 .668。 then it worked again.然后它又起作用了。 But I'm not seeing improved performane over the version without the extension behaviour so I'm still in doubt.但是我没有看到没有扩展行为的版本的性能提高,所以我仍然怀疑。

I did add我确实添加了

ProtoBuf.Serializer.PrepareSerializer<Article>(); 

to the service but it did not help.服务,但它没有帮助。

Still not sure what to do to check if the Article objects are serialized through the protobuf-net.dll software.仍然不确定如何检查 Article 对象是否通过 protobuf-net.dll 软件序列化。

Finally figured it all out by letting the service use .NET serialization and the client protobuf.最后通过让服务使用 .NET 序列化和客户端 protobuf 来解决所有问题。 then null would be returned.那么 null 将被返回。 Then made the service use protobuf serialization too and valid objects were returned.然后使服务也使用 protobuf 序列化并返回有效对象。

These are the correct config settings, the same structure for both client and service:这些是正确的配置设置,客户端和服务的结构相同:

 <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