WCF with HTTPS

WCF with HTTPS

Old forum URL: forums.lhotka.net/forums/t/11750.aspx


tcampney posted on Friday, December 14, 2012

I'm trying to deploy my first app with the newer CSLA (previously still using CSLA 2.x) and having an issue with https.  When just using http, it works but via https I'm getting this error:

{"The provided URI scheme 'https' is invalid; expected 'http'.\r\nParameter name: via"}

It is a WPF smart client application and the app server is hosted on IIS 6.  I know the cert on the server should be fine as this is the same server we use for all of our other old CSLA apps using remoting and those all work fine via https.  I've tried to look at the sample and checked the CSLA 4 books, but everything just seems to use http.  In my sever config below you'll see I've added security mode="Transport" as I've found after searching other sources about WCF, but still no luck.

Any hints would be MUCH appreciated!

Here is my client config:

 

 

    <add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla"/>
    <add key="CslaDataPortalUrl" value="https://test.acme.com/FormPFTest/WcfPortal.svc"/>       
    <add key="CslaPropertyChangedMode" value="Windows"/>   

and here is my server config:

    <system.serviceModel>
      <services>
        <service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
          <endpoint contract="Csla.Server.Hosts.IWcfPortal" binding="wsHttpBinding"/>
        </service>
        <service name="Csla.Server.Hosts.Silverlight.WcfPortal"
                 behaviorConfiguration="returnFaults" >
          <endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_IWcfPortal"
                    contract="Csla.Server.Hosts.Silverlight.IWcfPortal"/>
        </service>
      </services>
      <bindings>
        <basicHttpBinding>
          <binding name="basicHttpBinding_IWcfPortal"
                   maxReceivedMessageSize="2147483647"
                   maxBufferPoolSize="2147483647"
                   maxBufferSize="2147483647">

     <security mode="Transport">
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
      <message clientCredentialType="Certificate" algorithmSuite="Default" />
     </security>

     <readerQuotas maxBytesPerRead="2147483647"
                          maxArrayLength="2147483647"
                          maxStringContentLength="2147483647"
                          maxNameTableCharCount="2147483647"
                          maxDepth="2147483647"/>
          </binding>
        </basicHttpBinding>
        <wsHttpBinding>
          <binding name="wsHttpBinding_IWcfPortal"
                   maxReceivedMessageSize="2147483647">

     <security mode="Transport">
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
      <message clientCredentialType="Certificate" algorithmSuite="Default" />
     </security>

     <readerQuotas maxBytesPerRead="2147483647"
                          maxArrayLength="2147483647"
                          maxStringContentLength="2147483647"
                          maxNameTableCharCount="2147483647"
                          maxDepth="2147483647"/>
          </binding>
        </wsHttpBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior name="returnFaults">
              <serviceDebug includeExceptionDetailInFaults="true"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
    </system.serviceModel>

sergeyb replied on Friday, December 14, 2012

Make sure server and client settings match.  Set security mode=Transport on both sides.

tcampney replied on Friday, December 14, 2012

If I understand how to do it, I think I've set it on the server side with:

         <wsHttpBinding>
          <binding name="wsHttpBinding_IWcfPortal"
                   maxReceivedMessageSize="2147483647">

     <security mode="Transport">
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
      <message clientCredentialType="Certificate" algorithmSuite="Default" />
     </security>

     <readerQuotas maxBytesPerRead="2147483647"
                          maxArrayLength="2147483647"
                          maxStringContentLength="2147483647"
                          maxNameTableCharCount="2147483647"
                          maxDepth="2147483647"/>
          </binding>
        </wsHttpBinding> 

So how do I go about setting it on the client side besides specifying https in the url?  I haven't been able to find any reference and simply doing something like below just gives errors:

<add key="CslaDataPortalUrl" value="https://test.acme.com/FormPFTest/WcfPortal.svc" security mode="transport" />

Would you happen to have a sample of how to set it on the client side?

tcampney replied on Friday, December 14, 2012

I've tried a couple things piecing together some pieces from all samples which lead me to the below config on the client.  Still getting the same result.

<appSettings>
    <add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla"/>
    <add key="CslaPropertyChangedMode" value="Windows"/>
</appSettings>

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IWcfPortal" maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="Certificate" algorithmSuite="Default" />
          </security>         
          <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
        </binding>
      </wsHttpBinding>
    </bindings>   
   
    <client>
      <endpoint name="WcfDataPortal" address="https://test.acme.com/FormPF/WcfPortal.svc" binding="wsHttpBinding" contract="Csla.Server.Hosts.IWcfPortal" />
    </client>
 </system.serviceModel> 

 

sergeyb replied on Friday, December 14, 2012

Essentially your client and server must match, so you need to use the same bindingConfiguration element on both sides, and does not look like you do.

tcampney replied on Friday, December 14, 2012

I've just now done a copy/paste from my web.config binding to my app.config binding to be 100% sure they match.  I'm still having the same issue.  This is now by web.confg

<services>
  <service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
    <endpoint contract="Csla.Server.Hosts.IWcfPortal" binding="wsHttpBinding"/>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_IWcfPortal"
            maxReceivedMessageSize="2147483647">

   <security mode="Transport">
  <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
  <message clientCredentialType="Certificate" algorithmSuite="Default" />
   </security>

   <readerQuotas maxBytesPerRead="2147483647"
            maxArrayLength="2147483647"
            maxStringContentLength="2147483647"
            maxNameTableCharCount="2147483647"
            maxDepth="2147483647"/>
    </binding>
  </wsHttpBinding>
</bindings>

And this is my app.config

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_IWcfPortal"
            maxReceivedMessageSize="2147483647">

   <security mode="Transport">
  <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
  <message clientCredentialType="Certificate" algorithmSuite="Default" />
   </security>

   <readerQuotas maxBytesPerRead="2147483647"
            maxArrayLength="2147483647"
            maxStringContentLength="2147483647"
            maxNameTableCharCount="2147483647"
            maxDepth="2147483647"/>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint name="WcfDataPortal"
            address="https://test.acme.com/FormPF/WcfPortal.svc"
            binding="wsHttpBinding"
            contract="Csla.Server.Hosts.IWcfPortal" />
</client> 

With the copy/paste, they are now 100% identical but still having the same issue.  I feel like I'm going crazy :-)

tcampney replied on Friday, December 14, 2012

OK, I finally found it.  I found this link http://social.msdn.microsoft.com/Forums/eu/wcf/thread/ba6e21a7-9ab3-46b5-8240-5e3175af09ff which pointed out what I was missing.  In both the client and server configs, it seems to require the bindingConfiguration setting as well as binding setting.  After adding that, it all worked.  Just for anyone else's future reference below are my latest configs which now work. 

App.config

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_IWcfPortal"
            maxReceivedMessageSize="2147483647">

   <security mode="Transport">
  <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
  <message clientCredentialType="Certificate" algorithmSuite="Default" />
   </security>

   <readerQuotas maxBytesPerRead="2147483647"
            maxArrayLength="2147483647"
            maxStringContentLength="2147483647"
            maxNameTableCharCount="2147483647"
            maxDepth="2147483647"/>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint name="WcfDataPortal"
            address="https://test.acme.com/FormPF/WcfPortal.svc"
            binding="wsHttpBinding"
   bindingConfiguration ="wsHttpBinding_IWcfPortal"
            contract="Csla.Server.Hosts.IWcfPortal" />
</client>

 

Web.confg

<services>
  <service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
    <endpoint contract="Csla.Server.Hosts.IWcfPortal" binding="wsHttpBinding" bindingConfiguration ="wsHttpBinding_IWcfPortal"/>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_IWcfPortal"
            maxReceivedMessageSize="2147483647">

   <security mode="Transport">
  <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
  <message clientCredentialType="Certificate" algorithmSuite="Default" />
   </security>

   <readerQuotas maxBytesPerRead="2147483647"
            maxArrayLength="2147483647"
            maxStringContentLength="2147483647"
            maxNameTableCharCount="2147483647"
            maxDepth="2147483647"/>
    </binding>
  </wsHttpBinding>
</bindings>

Copyright (c) Marimer LLC