[英]WCF Won't Work Over HTTPS
我查看了所有其他解决方案,但没有一个正在运行。 我正在使用IIS托管WCF服务。 以下是我的web.config(我添加WCF服务时的默认设置):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
一切都很好,我可以使用http://www.domain.com/path/service.svc和https://www.domain.com/path/service.svc在浏览器中访问我的wcf服务 - 现在我添加了一个Windows控制台应用程序中对https://www.domain.com/path/service.svc的 Web引用,以下内容位于我的app.config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="defaultBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://www.domain.com/path/service.svc" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding" contract="DomainExt.IExt" name="BasicHttpBinding_IExt" />
</client>
</system.serviceModel>
</configuration>
以下代码是我用来测试服务的代码:
public static String DoPing()
{
ExtClient client = new ExtClient("BasicHttpBinding_IExt", "https://www.domain.com/path/service.svc");
return client.DoPing();
}
运行后我得到以下异常:
在https://www.domain.com/path/service.svc上没有可以接受该消息的端点监听。 这通常是由错误的地址或SOAP操作引起的。 有关更多详细信息,请参阅InnerException(如果存在)。
内部异常状态:
“远程服务器返回错误:(404)Not Found。”
此服务在http上正常工作但在https上失败。 我怎样才能解决这个问题? 请注意,我正在使用Windows控制台而不是通过ASP.NET访问此服务; ASP.NET仅托管WCF服务。
尝试设置httpsGetEnabled =“true”而不是httpGetEnabled
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" />
编辑:我也很好奇为什么你选择BasicHttpBinding,如果你使用SSL。 为什么不使用WsHttpBinding?
EDIT2:您是否在主机配置文件中缺少<services>
节点? 我不认为你可以创建没有一个客户端。 你可以右键单击你的app.config文件并在那里配置它...像这样:
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint address="" binding="defaultBasicHttpBinding" bindingConfiguration="basicBinding" contract="IMyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.