我的IIS无法识别我的WCF自定义绑定

时间:2011-03-09 09:58:30

标签: wcf wcf-binding

今天,我在使用custom binding托管我的自定义服务主机时遇到问题。我试图实现ServiceHostFactory但是当我右键单击以在浏览器中查看时,出现错误,因为IIS无法识别我的自定义绑定(duplexHttpBinding)。

我的web.config就在这里:

<services>
        <service name="TestWcf.Service1"
            behaviorConfiguration="Service1Behavior">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:8888/Service1"/>
                </baseAddresses>
            </host>
            <endpoint
                address="http://localhost:9999/Service1"
                binding="duplexHttpBinding"
                bindingConfiguration="binding1"
                contract="TestWcf.IService" />
        </service>
    </services>

    <bindings>
        <duplexHttpBinding>
            <binding name="binding1"
                     closeTimeout="00:01:00"
                     openTimeout="00:01:00"
                     receiveTimeout="24.20:31:23.6470000"
                     sendTimeout="02:01:00"
                     session="ReliableSession"
                     sessionTimeout="00:10:00"
                     maxUndeliveredMessages="100"
                     maxMessagesInBatch="10"
                     maxPollingReplyInterval="00:02:00">
            </binding>
        </duplexHttpBinding>
    </bindings>

    <behaviors>
        <serviceBehaviors>
            <behavior name="Service1Behavior">
                <serviceMetadata httpGetEnabled="True" />
                <serviceDebug includeExceptionDetailInFaults="True" />
            </behavior>
        </serviceBehaviors>
    </behaviors>

和dervied类中的代码在这里:

public class CustomServiceHost : ServiceHostFactory
{
    public override ServiceHostBase CreateServiceHost(string service, Uri[] baseAddresses)
    {
        DuplexHttpBinding binding = new DuplexHttpBinding();
        binding.Name = "binding1";

        Uri baseAddress = new Uri("http://localhost:8888/Service1");
        Uri address = new Uri("http://localhost:9999/Service1");


        ServiceHost serviceHost = new ServiceHost(typeof(Service1), baseAddresses);
        serviceHost.AddServiceEndpoint(typeof(IService1), binding, address);

        return serviceHost;
    }
}

并在SVC文件中

<%@ ServiceHost Language="C#" Debug="true" Service="TestWcf.Service1" Factory="TestWcf.CustomServiceHost" %>  

我是否会错过上下文中的内容?

谢谢。

1 个答案:

答案 0 :(得分:0)

您必须在配置文件中将新绑定注册为binding extension