在使用SVCUTIL生成WCF服务客户端代理类时:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>svcutil.exe /out:c:/Clie
ntCode.cs /config:c:/app.config https://localhost/TransportSecurity/CalculatorSe
rvice.svc
出现错误信息:
使用SVCUTIL生成客户端代理类时:元数据包含无法解析的引用:“https: 无法为 SSL/TLS 安全通道与颁发机构“localhost”建立信任关系。基础连接已经关闭: 未能为 SSL/TL 根据验证过程,远程证书无效。
这是由于证书的问题导致的,解决办法是添加可信证书后,把SVCUTIL命令的localhost地址改为实际PC名,而且必须要在WCF配置文件中使用<serviceMetadata httpGetEnabled="true"/>打开Metadata才行。
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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>
解决后的命令如下:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>svcutil.exe /out:c:/ClientCode.cs /config:c:/app.config https://eric-pc.tycofs.com/TransportSecurity/Cal
culatorService.svc