简体   繁体   English

自我托管的WCF服务无法通过HTTPS进行答复,但是HTTP可以工作

[英]Self hosted WCF service doesn''t reply over HTTPS but HTTP works

I have a self hosted WCF service which works fine when called with wsHttpBinding or basicHttpBinding over HTTP. 我有一个自托管的WCF服务,当通过HTTP通过wsHttpBinding或basicHttpBinding调用时,它可以正常工作。 The clients will include Windows Phone -devices over the Internet and because they can't utilize wsHttpBinding and we definitely need more security than basicHttpBinding offers I've tried to use TransportWithMessageCredential. 客户端将包括Internet上的Windows Phone设备,因为它们不能利用wsHttpBinding,而且我们肯定比我尝试使用TransportWithMessageCredential的basicHttpBinding提供的安全性更高。 When using HTTP everything works great but if I switch the client to HTTPS I get these in VS: "There was no endpoint listening at https://..." and "The remote server returned an error: NotFound." 使用HTTP时,一切正常,但是如果我将客户端切换为HTTPS,则会在VS中获得这些信息: “没有端点在https:// ...侦听”“远程服务器返回错误:未找到”。

I enabled service trace and it says that it opened the HTTPS-port without any problems and when I check netstat -an it confirms that the port really is open. 我启用了服务跟踪,它说它没有任何问题地打开了HTTPS端口,并且当我检查netstat -an时,它确认该端口确实是打开的。 HTTP and wsHttpBinding calls to the service work great and they generate events to the log but these HTTPS -calls don't show up there at all. 对服务的HTTP和wsHttpBinding调用工作得很好,并且它们会向日志生成事件,但是这些HTTPS调用根本不会出现在日志中。 I also can't get the metadata via HTTPS although it is enabled. 尽管启用了HTTPS,但我也无法通过HTTPS获得元数据。

The client and server are on the same machine and certificate is self-signed but it works with wsHttpBinding. 客户端和服务器位于同一台计算机上,并且证书是自签名的,但可与wsHttpBinding一起使用。

Here is the service config: 这是服务配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="xyzSecuredBehavior" name="x.x.xService">
        <endpoint address="/basic" binding="basicHttpBinding" bindingConfiguration="xyzBasicBinding"
                      contract="x.x.IxService" />
        <endpoint address="/secure" binding="basicHttpBinding" bindingConfiguration="xyzBasicBindingSecure"
                      contract="x.x.IxService" />
        <host>
          <baseAddresses>
            <add baseAddress="https://10.10.0.188:3003/xService" />
            <add baseAddress="http://10.10.0.188:3001/xService" />
          </baseAddresses>
        </host>
      </service>
    </services>

    <bindings>
      <wsHttpBinding>
        <binding name="customAuthenticationBinding" maxReceivedMessageSize="1000000" closeTimeout="23:59:59" openTimeout="23:59:59" receiveTimeout="23:59:59" sendTimeout="23:59:59">
          <readerQuotas maxDepth="1000000" maxStringContentLength="1000000" maxArrayLength="1000000" maxBytesPerRead="1000000" maxNameTableCharCount="1000000" />
          <security mode="Message">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="xyzBasicBinding" maxBufferSize="1000000" maxBufferPoolSize="1000000" maxReceivedMessageSize="1000000">
          <readerQuotas maxDepth="1000000" maxStringContentLength="1000000" maxArrayLength="1000000" maxBytesPerRead="1000000" maxNameTableCharCount="1000000" />
          <security mode="None">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
        <binding name="xyzBasicBindingSecure" maxBufferSize="1000000" maxBufferPoolSize="1000000" maxReceivedMessageSize="1000000">
          <readerQuotas maxDepth="1000000" maxStringContentLength="1000000" maxArrayLength="1000000" maxBytesPerRead="1000000" maxNameTableCharCount="1000000" />
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>

        <behavior name="xyzSecuredBehavior">
          <serviceCredentials>
            <serviceCertificate findValue="xyzTestCert" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="z.z.AuthenticationManager, z.zz" />
            <windowsAuthentication allowAnonymousLogons="false"/>
          </serviceCredentials>
          <serviceAuthorization serviceAuthorizationManagerType="z.z.AuthorizationManager, z.zz" />
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="1000000000" />
        </behavior>

        <behavior name="xyzBasicBehavior" >
          <serviceAuthorization serviceAuthorizationManagerType="z.z.AuthorizationManager, z.zz" />
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="1000000000" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>

And this is the client config: 这是客户端配置:

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IxService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
            <binding name="BasicHttpBinding_IxService1" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="TransportWithMessageCredential" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://10.10.0.188:3001/xService/basic"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IxService"
            contract="ServiceReference1.IxService" name="BasicHttpBinding_IxService" />
        <endpoint address="https://10.10.0.188:3003/xService/secure"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IxService1"
            contract="ServiceReference1.IxService" name="BasicHttpBinding_IxService1_secure" />
    </client>
</system.serviceModel>

Any help is appreciated as I have already wasted a good day or two on this and googling and fiddling with the settings has led to nothing. 感谢您的帮助,因为我已经在此浪费了上一两天的时间,并且对设置进行谷歌搜索和摆弄也无济于事。

this is already answerd so , i am not answering it here, instead giving you the link 这个已经被回答了,所以,我在这里不回答,而是给你链接

http://www.codeproject.com/Articles/36705/7-simple-steps-to-enable-HTTPS-on-WCF-WsHttp-bindi http://www.codeproject.com/Articles/36705/7-simple-steps-to-enable-HTTPS-on-WCF-WsHttp-bindi

I found the solution to this problem. 我找到了解决此问题的方法。 Because the service is self hosted I needed to manually apply the certificate to the application. 因为该服务是自托管的,所以我需要手动将证书应用于应用程序。 It wasn't enough that it was specified in the server config. 仅在服务器配置中指定还不够。

Detailed instructions can be found here: http://allen-conway-dotnet.blogspot.fi/2012/02/applying-and-using-ssl-certificate-with.html 可以在以下位置找到详细说明: http : //allen-conway-dotnet.blogspot.fi/2012/02/applying-and-using-ssl-certificate-with.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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