简体   繁体   English

如何在不创建新客户端或破坏现有客户端的情况下使WCF服务既是HTTP又是HTTPS

[英]how to make a WCF Service that is only HTTP as also HTTPS without creating new or breaking existing clients

I have a WCF Service that is using basicHttpBinding. 我有一个正在使用basicHttpBinding的WCF服务。 That is exposed as HTTP to many clients. 这作为HTTP公开给许多客户端。

Now our requirement is to expose this service as HTTPS to few new clients while we shouldn't break existing clients that consume over http. 现在,我们的要求是将该服务作为HTTPS公开给少数几个新客户端,同时我们不应该破坏通过http进行消费的现有客户端。

I came across detecting the type of security programmatically and then expose, but is there any other better and easy way for me to do that? 我遇到了以编程方式检测安全类型,然后公开的方法,但是还有其他更好,更简便的方法吗? Just with the endpoints configuration etc? 仅使用端点配置等?

I am fairly new to these areas, please help with an example 我是这些领域的新手,请提供示例

Yes there is a better solution as you mentioned with configuration which I have done two days ago for some our services. 是的,正如您在配置中提到的那样,还有一个更好的解决方案,我两天前就为我们的某些服务做了配置。

Add basicHttpBinding like below: 添加basicHttpBinding如下所示:

<basicHttpBinding>
  <binding allowCookies="true" openTimeout="00:00:10" maxReceivedMessageSize="20000000">
    <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000" />
    <security mode="None" />
  </binding>
  <binding name="secureBasicHttpBinding">
    <security mode="Transport">
      <transport clientCredentialType="None"/>
    </security>
  </binding>
</basicHttpBinding>

and service end point: 和服务终点:

<service  name="ServiceName">
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" bindingConfiguration="secureBasicHttpBinding" contract="your service contract">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost/Service.svc"/>
    </baseAddresses>
  </host>
</service>

and in IIS you just need add valid certificate and enable it, https use secureBasicHttpBinding and http use default basic httpConfiguration . 在IIS中,您只需要添加有效的证书并启用它, https使用secureBasicHttpBindinghttp使用默认的基本httpConfiguration

I have tested it before an now some client using that service in https some other are using http . 我已经测试过它,现在有些客户端在https使用该服务,而另一些客户端则使用http

Tip: 小费:

In local mode there is error while hosting WCF services by above config so I came to this conclusion to put that config in release mode not in debug mode, because the https is enable on working server. 在本地模式下,通过上述配置托管WCF服务时会出错,因此我得出以下结论,将该配置置于release模式而不是debug模式,因为在工作服务器上启用了https

so in release config have something like (to be transferred after publishing): 因此在release config中有类似的内容(在发布后将被传输):

<service  name="ServiceName" xdt:Locator="Match(name)" xdt:Transform="Replace">
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" bindingConfiguration="secureBasicHttpBinding" contract="your service contract">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost/AAA/Service.svc"/>
    </baseAddresses>
  </host>
</service>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM