2012-03-01 68 views
0

嗨,客户端CustomMessageInspector,如何从exe文件中让这段代码的工作?

我上运行服务端CustomMessageInspector,现在我需要在同一客户端支持。然而,在客户端中是不是以同样的方式实现的。我发现这个代码:

https://gist.github.com/1076635

但我有一个很难得到这个从WinForm的项目内运行,我真的不得不把这个类库来得到它的工作?

BestRegards

编辑1:

这是我服务的instanciation怎么看起来像在客户端。

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(); 

这是我当前的行为标签看起来像在的app.config:

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

你不应该需要把它放在一个类库它的功能有关您遇到的问题/错误的一些信息可能会有所帮助。 – luksan 2012-03-04 05:32:49

回答

0

编辑

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(); 
+0

请参阅我的Edit1。我如何在此包含您的解决方案?请注意,我需要设置msxItemInObjectGraph。 – Banshee 2012-03-01 11:42:35

+0

你给了他实例化服务的代码,他正在尝试创建一个双工客户端。 – luksan 2012-03-04 05:33:30

+0

我已编辑答案。希望能帮助到你! – pamidur 2012-03-16 14:24:17