【问题标题】:My IIS does not recognize my WCF custom binding我的 IIS 无法识别我的 WCF 自定义绑定
【发布时间】:2011-03-09 09:58:29
【问题描述】:

今天,我在使用 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" %>  

我是否错过了上下文中的某些内容?

谢谢。

【问题讨论】:

    标签: wcf wcf-binding


    【解决方案1】:

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

    【讨论】:

    • 非常感谢:完成后,我仍然发现错误“没有协议绑定与给定地址“localhost:9999/Service1”匹配。协议绑定是在 IIS 或 WAS 配置中的站点级别配置的。”对此有何建议?
    • 您正在使用 Https。在这种情况下,您的自定义绑定必须使用 httpsTransport 通道。绑定配置中是否有任何安全元素?如果是,则必须将其配置为传输模式。
    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    相关资源
    最近更新 更多