【问题标题】:Is it possible to return different wsdls for different contracts on the same service?是否可以为同一服务的不同合同返回不同的 wsdl?
【发布时间】:2011-10-11 10:23:09
【问题描述】:

我有一个 WCF 服务在两个不同的端点上实现两个合同。我希望客户端能够指向一个端点(而不是服务的基地址)并获取仅用于在该端点上实现的合同的 wsdl(而不是包含所有合同的 wsdl)。

这可能吗?如果可以,如何实现?

【问题讨论】:

    标签: wcf wsdl


    【解决方案1】:

    而不是如下所示设置服务(如果托管在 IIS 中,则使用单个 SVC 文件)

    <services>
        <service name="YourOrg.YourService">
    
            <endpoint address=""
                      binding="wsHttpBinding"
                      contract="YourOrg.IYourServiceThisContract" />
            <endpoint address="That"
                      binding="wsHttpBinding"
                      contract="YourOrg.IYourServiceThatContract" />
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange"/>
        </service>
    </services>
    

    将每个合同设置为单独的服务(在同一个 IIS 网站中具有自己的 SVC 文件)

    <services>
        <service name="YourOrg.ThisService">
    
            <endpoint address=""
                      binding="wsHttpBinding"
                      contract="YourOrg.IYourServiceThisContract" />
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange"/>
        </service>
    
        <service name="YourOrg.ThatService">
    
            <endpoint address=""
                      binding="wsHttpBinding"
                      contract="YourOrg.IYourServiceThatContract" />
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange"/>
        </service>
    </services>
    

    【讨论】:

    • 这是否意味着它们必须在不同的端口上?
    • 在 IIS 中默认情况下,他们将使用与答案中显示的配置相同的端口。可以在 IIS 中为具有主机标头的同一“网站”使用不同的端口。由于 WCF 不是真正的“URL 感知”,它不会很有用。
    • 我应该澄清这个问题 - 它不是 IIS 托管的,并且具有动态配置(因此它也不在配置文件中)。您的配置建议是否意味着我需要创建单独的服务主机?
    • 是的,WCF 要求每个服务定义都有自己的主机。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    • 2021-07-09
    • 1970-01-01
    • 2019-06-20
    相关资源
    最近更新 更多