WCF 在 http 和 https 上都具有自定义绑定

发布于 2024-11-10 15:26:36 字数 1244 浏览 3 评论 0原文

我有一个带有自定义绑定的 WCF 服务,它在 http 或 https 上运行良好。但我完全不知道如何才能使其在 http 和 https 上都可用?

也可以这样做吗?

这是我在 web.config 中的配置。

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<behaviors>
    <serviceBehaviors>
        <behavior name="">
            <serviceMetadata httpsGetEnabled="true" />                    
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>         
    </serviceBehaviors>
</behaviors>
<bindings>
    <customBinding>                     
        <binding name="customBinding0">
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">                           
        <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
            contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service>      
</services>

谢谢

I have a WCF service with custombinding and it is working fine on either http or https. But I have totally no idea about how can I make it available on both http and https?

Also is it possible to do that?

Here's my configuration in web.config.

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<behaviors>
    <serviceBehaviors>
        <behavior name="">
            <serviceMetadata httpsGetEnabled="true" />                    
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>         
    </serviceBehaviors>
</behaviors>
<bindings>
    <customBinding>                     
        <binding name="customBinding0">
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">                           
        <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
            contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service>      
</services>

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

远昼 2024-11-17 15:26:36

您需要有两个端点,一个用于 HTTP,另一个用于 HTTPS。它应该工作得很好。

<bindings>
    <customBinding>
        <binding name="customBindingHTTP">
            <binaryMessageEncoding />
            <httpTransport />
        </binding>
        <binding name="customBindingHTTPS">
            <binaryMessageEncoding />
            <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTP"
                  contract="MyWCFService" />
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTPS"
                  contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service> 
</services> 

You'll need to have two endpoints, one for HTTP and another for HTTPS. It should work just fine.

<bindings>
    <customBinding>
        <binding name="customBindingHTTP">
            <binaryMessageEncoding />
            <httpTransport />
        </binding>
        <binding name="customBindingHTTPS">
            <binaryMessageEncoding />
            <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTP"
                  contract="MyWCFService" />
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTPS"
                  contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service> 
</services> 
嘿看小鸭子会跑 2024-11-17 15:26:36

我在代码中做了我的:

var basicbinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
CustomBinding binding = new CustomBinding();
binding.Elements.Add(new CustomTextMessageBindingElement("iso-8859-1"));

var bindingElements = basicbinding.CreateBindingElements().ToList();
var encodingElement = bindingElements.OfType<MessageEncodingBindingElement>().FirstOrDefault();
if (encodingElement != null)
{
    bindingElements.Remove(encodingElement);
}
binding.Elements.AddRange(bindingElements.ToArray());

I did mine in the code:

var basicbinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
CustomBinding binding = new CustomBinding();
binding.Elements.Add(new CustomTextMessageBindingElement("iso-8859-1"));

var bindingElements = basicbinding.CreateBindingElements().ToList();
var encodingElement = bindingElements.OfType<MessageEncodingBindingElement>().FirstOrDefault();
if (encodingElement != null)
{
    bindingElements.Remove(encodingElement);
}
binding.Elements.AddRange(bindingElements.ToArray());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文