【问题标题】:there was no endpoint listening at https://wserver:442/service1.svc在 https://wserver:442/service1.svc 没有端点监听
【发布时间】:2015-06-11 00:09:52
【问题描述】:

我正在尝试使用自签名 SSL 设置 WCF 服务。

我可以浏览到 HTTPS,它会显示元数据,我可以创建一个服务引用。

但是它抛出异常:https://wserver:442/service1.svc 没有端点监听 可以接受该消息。

wserver 是我的服务器的名称,但我没有在任何地方使用它,所以我不知道它是从哪里获取的?

我的服务器 Webhost.config(我认为问题可能出在哪里)是:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="Binding1">
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>

    </bindings>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="AutoSenderWCFService.AutoSenderService">
        <endpoint binding="wsHttpBinding" bindingConfiguration="Binding1"
          contract="AutoSenderWCFService.IService1" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceCredentials>

            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="AutoSenderWCFService.MyValidator, AutoSenderWCFService"/>

          </serviceCredentials>

          <!-- 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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

或者我在自签名 SSL 上犯了一个错误?

我的客户端只是:

    private void button1_Click(object sender, EventArgs e)
    {

        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
        client.ClientCredentials.UserName.UserName = "test";
        client.ClientCredentials.UserName.Password = "testPassword";            
        ServiceReference1.Contact[] test = client.GetDrivers();

    }
}

【问题讨论】:

  • 您的服务是如何托管的? 442端口是否正确? - HTTPS 的默认值为 443。连接 URL 来自客户端代理 - 这是它可能来自的唯一位置,因为您没有明确指定要连接的端点。
  • 我已经有一台在 443 上运行 HTTPS 的服务器,所以我使用了 442。
  • 好的。要解决此问题,我建议您在客户端启用 WCF 跟踪并查看输出。
  • 配置是webhost.config还是web.config?你说的是前者,但应该是后者——这是你的信息中的错字吗?

标签: c# wcf web-services


【解决方案1】:

发生这种情况有几个原因。由于您有一个在 443 上运行的默认 https,因此您将端口 442 用于 https 为您的服务。

您是否对 442 端口上的 https 进行了任何映射?您可以使用 netsh 命令来完成,如下所示:

C:\> netsh http add sslcert ipport=0.0.0.0:442 certhash=6797aea29440de9389bc636e15a35b741d8c22a3 appid={2e80948d-9ae6-42c9-ad33-294929333965}

您的证书哈希需要是指纹 id,appid 是 WCF 项目 dll 的哈希 id,您将在您的 assembly.cs 文件中创建一个并在构建项目之前包含它。

接下来,您定义了一个可以删除的 mex 端点,并将您的 serviceMetaData 元素更改为具有 httpsGetEnabled ="true"httpGetEnabled="false"

现在请务必浏览您的服务页面,看看是否正常。

接下来在您的客户端代码中调用 WCF 服务之前,您需要执行以下步骤以绕过证书验证检查:

    System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
                                                                             {
                                                                                 return true;
                                                                             };

使用上述代码的原因是因为您使用的是自签名证书。如果您拥有由某个受信任的机构颁发的证书,那么您的客户端应用程序中不需要有上述代码。

【讨论】:

    【解决方案2】:

    如上所示,我在服务器端 Web.Config 文件的 WCF 服务中更改了 HTTPSEnabled 和 HTTPEnabled 属性。 它可以正常工作而不会发出“没有端点正在监听...”问题。 由于网站严格要求 SSL,因此 HTTPEnabled 属性应设置为 false。 感谢您在上面发布解决方案。

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时对自己的帖子发表评论,一旦您拥有足够的声誉,您就可以对任何帖子发表评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 2014-06-23
    相关资源
    最近更新 更多