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

时间:2012-05-18 00:02:29

标签: c# wcf web-services

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

    }
}

2 个答案:

答案 0 :(得分:0)

出现这种情况的原因有两个。由于您具有在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是您在assembly.cs文件中的WCF项目dll的哈希ID,否则在构建项目之前创建一个并包含。

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

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

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

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

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

答案 1 :(得分:0)

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

相关问题