简体   繁体   English

WCF无法通过HTTPS工作

[英]WCF Won't Work Over HTTPS

I have looked through all of the other solutions and none of them are working. 我查看了所有其他解决方案,但没有一个正在运行。 I am hosting a WCF service using IIS. 我正在使用IIS托管WCF服务。 The following is my web.config (the default for when I added a WCF service): 以下是我的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>

All is good and I can access my wcf service in the browser using http://www.domain.com/path/service.svc and https://www.domain.com/path/service.svc - now I add a web reference to https://www.domain.com/path/service.svc in a windows console application and the following is in my app.config: 一切都很好,我可以使用http://www.domain.com/path/service.svchttps://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>

The following code is what I am using to test the service: 以下代码是我用来测试服务的代码:

public static String DoPing()
{
     ExtClient client = new ExtClient("BasicHttpBinding_IExt", "https://www.domain.com/path/service.svc");
     return client.DoPing();
}

After I run this I get the following exception: 运行后我得到以下异常:

There was no endpoint listening at https://www.domain.com/path/service.svc that could accept the message. https://www.domain.com/path/service.svc上没有可以接受该消息的端点监听。 This is often caused by an incorrect address or SOAP action. 这通常是由错误的地址或SOAP操作引起的。 See InnerException, if present, for more details. 有关更多详细信息,请参阅InnerException(如果存在)。

The inner-exception sates: 内部异常状态:

"The remote server returned an error: (404) Not Found." “远程服务器返回错误:(404)Not Found。”

This service works fine over http but fails on https. 此服务在http上正常工作但在https上失败。 How can I fix this? 我怎样才能解决这个问题? Please note that I'm accessing this service using Windows Console and NOT through ASP.NET; 请注意,我正在使用Windows控制台而不是通过ASP.NET访问此服务; ASP.NET is only hosting the WCF service. ASP.NET仅托管WCF服务。

Try setting httpsGetEnabled ="true" rather than httpGetEnabled 尝试设置httpsGetEnabled =“true”而不是httpGetEnabled

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpsGetEnabled="true" />

EDIT: I'm also curious why you chose the BasicHttpBinding if you're using SSL. 编辑:我也很好奇为什么你选择BasicHttpBinding,如果你使用SSL。 Why not use the WsHttpBinding? 为什么不使用WsHttpBinding?

EDIT2: Are you missing a <services> node in your host config file? EDIT2:您是否在主机配置文件中缺少<services>节点? I wouldn't think you could create a client without one. 我不认为你可以创建没有一个客户端。 You can right click on your app.config file and configure it there... Something like this: 你可以右键单击你的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM