WCF - 定制 WDSL 生成
我花了几个小时尝试在 wsdl 生成中进行一些自定义,但没有结果。 我陷入困境主要是因为我找不到我想做的事情的清晰样本(我可能错过了一些东西)。
让我们进入正题:我想自定义生成的 WSDL。 我发现的最相关的文章是关于向现有服务添加属性以添加行为,像这样文章。
我想要做的是能够分析 OperationContract 并生成附加的 xsd(如果需要)。
我的问题是:
- 如何在不添加属性的情况下添加或拦截现有的 WSDL 生成?
- 如何在配置文件中配置该组件?
我不想更改 svcutil.exe 使用元数据的方式,只需在生成的 wsdl 中添加一些“即时”的 ComplexType 即可。
感谢您的建议!
I spent hours trying to do some customizations in the wsdl generation, without results.
I got stuck mainly because I could not find a clear sample for what I want to do (I may have missed something).
Let's got to the point : I want to customize the generated WSDL.
The most relevant articles I found are about adding attributes to existing Services to add behavior, like this article.
What I want to do is being able to analyze the OperationContract and generate and additionnal xsd if required.
My questions are :
- How can you add or intercept existing WSDL generation without adding attributes ?
- How do I configure this component in the config file ?
I don't want to change the way the metadata are consumed by svcutil.exe, just add some ComplexType 'on-the-fly' in the generated wsdl.
Thanks for your suggestions !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要的是实现
IWsdlExportExtension.ExportContract
但 文档明确指出:对我来说,这意味着仅当通过合同或操作行为实现时才会调用此方法,这些行为通常由自定义属性定义,但您也应该能够在自定义初始化中分配这些行为。 这是示例从配置文件配置的端点的 WSDL 扩展的 (配置仅提供整个服务和端点的行为)。我相信(但没有测试)您可以做类似的扩展,其中包括:
IWsdlExportExtension
和ExportContract
的端点行为>IEndpointBehavior
和ApplyDispatchBehavior
。在ApplyDispatchBehavior
中,您将使用serviceEndpoint.Contract.Behaviors
添加合约行为,或使用serviceEndpoint.Contract.Operations[x].Behaviors
添加操作行为。BehaviorExtensionElement
来从配置文件定义新的端点行为。What you need is implementing
IWsdlExportExtension.ExportContract
but the documentation clearly states:For me it means that this method is called only when implemented by contract or operation behavior which is usually defined by custom attribute but you should be also able to assign these behaviors in custom initialization. Here is the example of WSDL extension for endpoint configured from configuration file (configuration offers only behaviors for whole service and endpoints). I believe (but didn't test it) that you can do similar extension which will consist of:
IWsdlExportExtension
andExportContract
IEndpointBehavior
andApplyDispatchBehavior
. InApplyDispatchBehavior
you will useserviceEndpoint.Contract.Behaviors
to add contract behavior orserviceEndpoint.Contract.Operations[x].Behaviors
to add operation behavior.BehaviorExtensionElement
for defining your new endpoint behavior from configuration file.