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

问题描述 投票:0回答:1

我有最简单的WCF服务(visual studio template one),它可以正常使用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

我在这里的问题是为什么视觉工作室不能得到https://tar.tennis.com.au/testwcf/service1.svc并且http://10.21.100.129/testwcf/service1.svc没问题?

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

visual-studio wcf https
1个回答
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>

如果有什么我可以帮忙,请随时告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.