创建 WCF 绑定实例的 XML 表示
我正在尝试使用 WSHttpBinding.CreateBindingElements 方法 。
Binding wsHttpBinding = ...
BindingElementCollection beCollection = originalBinding.CreateBindingElements();
foreach (var element in beCollection)
{
customBinding.Elements.Add(element);
}
生成自定义绑定后,我想为该新的自定义绑定生成 XML 表示形式。 (与应用程序的 .config 文件中的 XML 表示形式相同)。
有办法做到这一点吗?
(我知道这个答案中引用的工具:https://stackoverflow.com/a/4217892/5688 ,但我需要可以在应用程序中调用的东西,而不依赖于云中的服务)
I'm trying to write code to convert a WCF wsHttpBinding to customBinding, using the method described on WSHttpBinding.CreateBindingElements Method
.
Binding wsHttpBinding = ...
BindingElementCollection beCollection = originalBinding.CreateBindingElements();
foreach (var element in beCollection)
{
customBinding.Elements.Add(element);
}
Once I have generated the custom binding, I want to generate an XML representation for that new custom binding. (The same XML representation that's found in an application's .config file).
Is there a way to do that?
(I'm aware of the tool referenced in this answer: https://stackoverflow.com/a/4217892/5688, but I need something I can call within an application and without depending on a service in the cloud)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在寻找的类是 System.ServiceModel.Description。 ServiceContractGenerator
为任何类型的 Binding 实例生成配置的示例:
此解决方案感觉像是黑客,因为需要生成空的临时文件,但它确实有效。
现在我必须寻找一种方法来拥有 System.Configuration.Configuration 的完全内存实例(也许通过编写我自己的实现)
The class I was looking for was System.ServiceModel.Description.ServiceContractGenerator
Exemple to generate a configuration for an instance of any kind of Binding:
This solution feels like a hack because of the need to generate empty temporary files, but it works.
Now I'll have to look for a way to have a fully in-memory instance of a System.Configuration.Configuration (maybe by writing my own implementation)
添加了缺少的代码部分:
// [...删除临时文件...]
Added missing code parts:
// [... delete the temporary files ...]