https://wserver:442/service1.svc 没有端点侦听

本文关键字:端点 service1 wserver https svc | 更新日期: 2023-09-27 18:34:37

我正在尝试使用自签名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();
    }
}

https://wserver:442/service1.svc 没有端点侦听

发生这种情况的原因有几个。由于您有一个在 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.cs否则创建一个并在生成项目之前包含。

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

现在确保浏览到您的服务页面,看看是否正常。

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

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

使用上述代码的原因是因为您使用的是自签名证书。如果你的证书已由某个受信任的颁发机构颁发,则无需在客户端应用中具有上述代码。

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