我有一个使用Add Service Reference生成的WCF客户端,问题是此客户端的类将与其配置文件一起嵌入到.msi(WIX项目)中。从msi中,代理无法识别配置文件。我想在msi以外的配置文件,并告诉代理从那里读取它的需求。为代理设置另一个配置文件
有什么办法可以达到这个目的吗?告诉代理从另一个配置获取它的数据而不是默认的数据?
一些想法或一些例子会很好。
感谢, 阿德里安娜
我有一个使用Add Service Reference生成的WCF客户端,问题是此客户端的类将与其配置文件一起嵌入到.msi(WIX项目)中。从msi中,代理无法识别配置文件。我想在msi以外的配置文件,并告诉代理从那里读取它的需求。为代理设置另一个配置文件
有什么办法可以达到这个目的吗?告诉代理从另一个配置获取它的数据而不是默认的数据?
一些想法或一些例子会很好。
感谢, 阿德里安娜
这是我做的: 从这个瓦苏给我,从样品,我在我的项目加入CustomClientChannel的链接。 我发现了2个错误: - 如果代理配置不具有行为 - 如果在配置文件中是多个端点,每个端点都带有绑定,则始终需要第一个绑定,而不管端点如何。
固定这样的:
//in CreateDescription() modify
if (serviceEndpoint.Binding == null)
{
serviceEndpoint.Binding = CreateBinding(selectedEndpoint.Binding, selectedEndpoint.BindingConfiguration, serviceModeGroup);
}
...
if (serviceEndpoint.Behaviors.Count == 0 && !String.IsNullOrEmpty(selectedEndpoint.BehaviorConfiguration))
{
AddBehaviors(selectedEndpoint.BehaviorConfiguration, serviceEndpoint, serviceModeGroup);
}
/// <summary>
/// Configures the binding for the selected endpoint
/// </summary>
/// <param name="bindingName"></param>
/// <param name="group"></param>
/// <returns></returns>
private Binding CreateBinding(string bindingName, string bindingConfiguration, ServiceModelSectionGroup group)
{
IBindingConfigurationElement be = null;
BindingCollectionElement bindingElementCollection = group.Bindings[bindingName];
if (bindingElementCollection.ConfiguredBindings.Count > 0)
{
foreach (IBindingConfigurationElement bindingElem in bindingElementCollection.ConfiguredBindings)
{
if (string.Compare(bindingElem.Name, bindingConfiguration) == 0)
{
be = bindingElem;
break;
}
}
Binding binding = null;
if (be != null)
{
binding = GetBinding(be);
be.ApplyConfiguration(binding);
}
return binding;
}
return null;
}
我们通过创建自定义的ChannelFactory并重写CreateDescription方法来完成它。然后,您可以通过
var lProxy = (IClientChannel)mYourChannelFactory.CreateChannel();
lProxy.Open()
瓦苏你好,非常感谢,把这个类在我的项目和它的工作......一些修正后......将我的帖子解释... – Adrya 2009-06-12 13:48:40