visual-studio - 在 Visual Studio 中向 WCF 服务添加服务引用失败
问题描述
我有最简单的 WCF 服务(Visual Studio 模板之一),它在 http 上运行良好,但在 https 上运行失败。下面是小细节。
这是它在 IIS 中的样子。
这是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 时的浏览器
这是我从域名 ping 时的浏览器。
在这一点上一切都很好。但是,当我尝试在 Visual Studio 中添加服务引用时,它使用 https 失败,但使用 http 成功。
这是 IP 之一(http)
这是域名一(https)
详细的错误信息是
我在这里遇到的问题是,为什么 Visual Studio 无法获取https://tar.tennis.com.au/testwcf/service1.svc并且可以使用http://10.21.100.129/testwcf/service1.svc?
肯定一个是http,另一个是https,但是为什么浏览器没有问题呢?
解决方案
我们需要添加额外的服务端点来支持 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>
如果有什么我可以帮忙的,请随时告诉我。
推荐阅读
- sql - 我们可以在视图上创建物化视图吗
- objective-c - 如何在 Xamarin 中实现 Treelist 下拉菜单?
- java - 从 PHP URL 处理 RecyclerView 中的空异常
- python - Python Regex:仅替换捕获的组
- java - 升级 Corda 后运行测试时出错 obj.javaClass.`package`
- java - 如何使用 mouseClicked 在循环内获取 JLabel 的值?
- ios - UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误
- dataframe - 八度:将数据帧转换为元胞数组
- javascript - 阿贾克斯。语法错误。无效字符
- bash - 列的总和,直到确定计数