一个端点,不同的绑定?

时间:2009-12-14 21:54:00

标签: wcf

有没有办法从单个端点公开服务,例如“https://mydomain.com/Myservice.svc” 但是能够有不同的绑定配置。

我知道端点在URL + Contract + Binding上必须是唯一的,但我想知道如何才能有多个绑定 没有为我想要支持的每个绑定复制所有.svc文件(因为IIS中的URL是文件夹或虚拟目录)

在示例中,我想要Http加密,Http没有加密..如果以后我没有建立securityContext,那么我必须复制4次我的svc文件来支持

一个人: establishSecuriTyContext = true 加密=真

一个人: establishSecuriTyContext = true 加密=错误

一个人: establishSecuriTyContext = true 加密=真

一个人: establishSecuriTyContext = false 加密=错误

依旧......

对我来说没有意义。

1 个答案:

答案 0 :(得分:0)

为每个端点引用唯一的绑定配置。此示例显示了如何使用NetNamedPipeBinding执行此操作,但您也可以将概念扩展到其他绑定。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netNamedPipeBinding>
                <binding name="default1" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
                    transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
                    maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="Transport">
                        <transport protectionLevel="EncryptAndSign" />
                    </security>
                </binding>
                <binding name="default2" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="infinite" sendTimeout="00:01:00" transactionFlow="false"
                    transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
                    maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="Transport">
                        <transport protectionLevel="EncryptAndSign" />
                    </security>
                </binding>
            </netNamedPipeBinding>
        </bindings>
        <services>
            <service name="MyService">
                <endpoint name="MyService1"
                    address="net.pipe://localhost/MyService1"
                    contract="NSITE.Services.Event.IMyService"
                    binding="netNamedPipeBinding" bindingConfiguration="default1" />
                <endpoint name="MyService2"
                    address="net.pipe://localhost/MyService2"
                    contract="NSITE.Services.Event.IMyService"
                    binding="netNamedPipeBinding" bindingConfiguration="default2" />
            </service>
        </services>
    </system.serviceModel>
</configuration>