在Visual Studio中将对WCF服务的服务引用添加到Visual Studio中失败

时间:2019-03-27 05:15:36

标签: visual-studio wcf https

我有最简单的WCF服务(Visual Studio模板之一),该服务在http上运行正常,但在https上运行失败。下面是很少的细节。

这是IIS中的外观。

enter image description here

这是web.config

<system.serviceModel>
<services>
  <service name="WcfService1.Service1">
    <endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1" />
    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

当我从ip ping它时,这里是浏览器

enter image description here

当我从域名ping它时,这是浏览器。

enter image description here

这一切都很好。但是,当我尝试在Visual Studio中添加服务引用时,它以https失败,但是以http成功。

这是ip one(http)

enter image description here

这是域名一(https)

enter image description here

详细错误消息是

enter image description here

我在这里的问题是,为什么Visual Studio无法掌握https://tar.tennis.com.au/testwcf/service1.svc并且对http://10.21.100.129/testwcf/service1.svc没问题?

肯定一个是http,另一个是https,但是为什么浏览器没有问题?

1 个答案:

答案 0 :(得分:0)

我们需要添加其他服务端点以支持https绑定。 有两种配置方法,请参考我的示例。
1。简化的配置

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http" />
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

2。添加使用传输安全性的https服务终结点。

<system.serviceModel>
    <services >
      <service name="WcfService1.Service1">
        <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1"></endpoint>
        <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="https"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="https">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

请随时告诉我是否有什么可以帮忙的。