客户端CustomMessageInspector,如何使此代码在exe文件中工作

本文关键字:exe 文件 工作 代码 CustomMessageInspector 何使此 客户端 | 更新日期: 2023-09-27 18:26:19

嗨,

我在服务端运行CustomMessageInspector,现在我需要在客户端运行。然而,Is在客户端中的实现方式不同。我发现了这个代码:

https://gist.github.com/1076635

但是我很难在winform项目中运行它,我真的必须把它放在类库中才能运行吗?

BestRegards

编辑1:

这就是我在客户端的服务状态。

    ClientService clientService = new ClientService();
    InstanceContext context = new InstanceContext(clientService);
    DuplexChannelFactory<MyApp.ServiceContracts.IMyAppClientService> factory = new DuplexChannelFactory<MyApp.ServiceContracts.IMyAppClientService>(context, connectionName);
    factory.Credentials.UserName.UserName = anvandarNamn;
    factory.Credentials.UserName.Password = password;
    return factory.CreateChannel();

这就是我当前的Behavior标签在app.config:中的样子

<behaviors>
  <endpointBehaviors>
    <behavior name="BasicBehavior">
      <CustomMessageInspector/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </endpointBehaviors>
</behaviors>

客户端CustomMessageInspector,如何使此代码在exe文件中工作

编辑

ClientService clientService = new ClientService();
clientService.Endpoint.Behaviors.Add(new YourBehaviorThatApplysYourExtension());
InstanceContext context = new InstanceContext(clientService);
DuplexChannelFactory<MyApp.ServiceContracts.IMyAppClientService> factory = new 
   DuplexChannelFactory<MyApp.ServiceContracts.IMyAppClientService>(context);
factory.Credentials.UserName.UserName = anvandarNamn;
factory.Credentials.UserName.Password = password;
return factory.CreateChannel();