Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
同一主机/端口上的Wcf HTTP和HTTPS_Wcf_Wcf Binding_Wcf Security - Fatal编程技术网

同一主机/端口上的Wcf HTTP和HTTPS

同一主机/端口上的Wcf HTTP和HTTPS,wcf,wcf-binding,wcf-security,Wcf,Wcf Binding,Wcf Security,你好, 我知道如何为http或https创建自托管wcf,但不能同时创建 我想要这2个URL的wcf: https://127.0.0.1:13070/ProxySips/ http://127.0.0.1:13070/ProxySips/ 目前,我有https的配置(带有一个证书:makecert+netsh),它可以正常工作: app.config <system.serviceModel> <bindings> <basicHttpBinding>

你好,

我知道如何为http或https创建自托管wcf,但不能同时创建

我想要这2个URL的wcf:

  • https://127.0.0.1:13070/ProxySips/
  • http://127.0.0.1:13070/ProxySips/
  • 目前,我有https的配置(带有一个证书:makecert+netsh),它可以正常工作:

    app.config

    <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttp" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="ProxySips_Wcf.Sips" behaviorConfiguration="ProxySips_Wcf.ProxySipsBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="https://127.0.0.1:13070/ProxySips/"   />
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding"
                  bindingConfiguration="basicHttp"
                  contract="ProxySips_Wcf.ISips"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ProxySips_Wcf.ProxySipsBehavior">
          <serviceMetadata  httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    
    可以帮我设置相同地址的http版本吗


    非常感谢

    您可以通过使用。使用多个端点,您可以通过多个协议(在您的情况下是HTTP和HTTPS)支持相同的服务

    因此,您需要添加以下
    服务行为

    <behavior name="MyUnsecureServiceBehavior">
         <serviceMetadata httpGetEnabled="true" />
         <serviceDebug includeExceptionDetailInFaults="false" />
         <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
    
    最后是以下
    地址
    配置:

    <service behaviorConfiguration="MyUnsecureServiceBehavior"
                             name="MyUnsecureService">
       <endpoint address="http://127.0.0.1:13070/ProxySips/"
                 binding="basicHttpBinding"
                 contract="ProxySips_Wcf.ISips"
                 bindingConfiguration="MyUnsecureBindingConfig" />
       <endpoint address="mex"
                 binding="mexHttpBinding"
                 contract="IMetadataExchange"/>
    </service>
    

    你好,德里克,谢谢你的帮助,但是当我把你的配置,我没有执行错误,但没有在http端点上发生任何事情。我应该创建一个新的主机服务吗?@Bob:我更新了我的答案,告诉你如何为你的主机应用程序指定要侦听的多个端点。无论哪种方式都要告诉我。这件事解决了吗?我试图弄清楚WCF是否可以同时在同一URI/端口上侦听http和https。到目前为止,我还没有做到。
    <basicHttpBinding>
      <binding name= MyUnsecureBindingConfig"
                     maxBufferPoolSize="2147483647" 
                     maxReceivedMessageSize="2147483647" 
                     messageEncoding="Text">
         <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                       maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                       maxNameTableCharCount="2147483647" />
         <security mode="None">
             <transport clientCredentialType="None" />
             <message establishSecurityContext="false" />
         </security>
    </basicHttpBinding>
    
    <service behaviorConfiguration="MyUnsecureServiceBehavior"
                             name="MyUnsecureService">
       <endpoint address="http://127.0.0.1:13070/ProxySips/"
                 binding="basicHttpBinding"
                 contract="ProxySips_Wcf.ISips"
                 bindingConfiguration="MyUnsecureBindingConfig" />
       <endpoint address="mex"
                 binding="mexHttpBinding"
                 contract="IMetadataExchange"/>
    </service>
    
    var httpsAddress = new Uri("https:// 127.0.0.1:13070/ProxySips/");
    var httpAddress = new Uri("http://127.0.0.1:13070/ProxySips/");
    var host = new ServiceHost(typeof(ProxySips_Wcf.Sips), 
                                new Uri[] { httpsAddress, httpAddress });
    host.Open();