WCF Bindings Needed For HTTPS

I just finished writing my first production WCF application, which worked very well until I deployed it to our production environment.  All of a sudden none of the WCF calls would work, and I would get a JavaScript "TestService is not defined" error.  When I look inside the JS service reference (in debug mode), I got the following error:

Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]

So apparently my WCF service registered itself as HTTPS (since it is over SSL), but my binding was only configured for HTTP.  The solution is to define a custom binding inside your Web.Config file and set the security mode to "Transport".  Then you just need to use the bindingConfiguration property inside your endpoint definition to point to your custom binding.  The entire HTTPS-enabled system.serviceModel section is below:

<system.serviceModel>
<behaviors>    
 <endpointBehaviors>
  <behavior name="TestServiceAspNetAjaxBehavior">
   <enableWebScript />
  </behavior>
 </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
 <service name="TestService">
  <endpoint address="" behaviorConfiguration="TestServiceAspNetAjaxBehavior"
   binding="webHttpBinding" bindingConfiguration="webBinding" contract="TestService" />
 </service>
</services>
 <bindings>
   <webHttpBinding>
     <binding name="webBinding">
       <security mode="Transport">
       </security>
     </binding>
   </webHttpBinding>
 </bindings>
</system.serviceModel>

Hopefully this will help someone who has the same problem.

52 Comments

  • Thank you, thank you, thank you.
    I was trying to fix the same issue with my WCF enabled web app and your solution helped me address the issue. A google search of "asp.net ajax wcf https" yielded your entry.

    Thanks again!!

  • I came across the same problem, and found your solution to be helpful. Thanks!

  • I was a bit worried when I found my service would work with ssl off and then I'd get 404/500 errors in production when I turned ssl on - this fixed my problem perfectly!

    Thanks very much :-)

  • This detail is good but am facing similar kind of issue using wsHttpBinding, any detail on service configuration entries to host WCF service using SSL would be helpful

  • thanks, worked a treat

  • Worked beautifully. Thanks a ton.

    Now what if I want to keep both configurations active - one for Http & one for Https? Do I define 2 bindings & 2 endpoints? For Http the security mode would be "None" & for Https "Transport". The only difference between the 2 endpoint elements' attributes would be the 2 binding types. Am I on the right track?

  • This solution works like a charm in the HTTPS.

    However, I am also interested in figuring out how to host the same webservice in both HTTP and HTTPS.


  • It turns out to be a very simple task to run the same service in both, HTTP and HTTPS:

    - Add new webHttpBinding and set its security mode to "None"
    - Add a new and point to the new webHttpBinding

  • Such a beautiful article.

    Just one note: after 3 hours we realized that webHttpBinding is not suitable for regular SOAP-based clients (one has to watch these bindings :) and we acknowledge that this is ASP.NET-centric blog). We switched webHttpBinding to basicHttpBinding and our SOAP-based clients were able to parse the generated WSDL and to consume the web service.

  • Thanks for this post, it solved my problem

  • Hey I am facing the same issue.

    My problem is i have to host wcf service in http and https

    I am using basichttpbinding but i am getting 500,404 errors for https.

    how do we know where the problem is?

  • You saved me with this solution. Thanks!

  • I'm uisng webHttpBinding to publish clientaccesspolicy.xml in WAS. Trying to apply your solution seemed great, but i'm still thrown on callback with cross-domain error.

    Have you any ideas?

  • sure... simple http_without_ssl works with webHttpBinding_witout_transport_security

  • Instead of


    you should try

  • Very Nice Article. It Solved My Problem.

  • Thanks, you solved my problem.

  • Your posting (and subsequent comments) were the perfect resolution to getting my WCF Service to respond on both HTTP and HTTPS. Thanks a million!

  • Thanks very much that solved my problem too.I was having problem while accessing methods of wcf service deployed on https.

    always gave http 404 error

  • Thanks!! This exactly solved my problem. Time and time again, Google searches bring me to your site for answers, and your answers are consistently among the most concise and direct. You know when you're looking for answers, do a search, hit a page, and you get that feeling the page will have the answer you need without a bunch of extraneous crap? I get that feeling when I see your entries.
    Thanks again.

  • This article saved my life. Had to push something to production and this was exactly what I was looking for.

    Thanks!

  • Fixed my issue! Thanks a bunch!

  • Thanks for this article.
    I am able to configure the Service. Now I need to build a client with WSDL (NOT svcutil, since I want the client to work with .net 2.0). For testing purpose I am using a local certificate. When I try to browse the service, it is coming without certificate error after installing the certificate in the client machine. (WCF service hosted in IIS and browsed using IE from a machine in the same network).
    My problem is when I run the wsdl command, it is thowing an error saying
    "- The underlying connection was closed: Could not establish trust relationship
    for the SSL/TLS secure channel.
    - The remote certificate is invalid according to the validation procedure.
    ". What is the way out ? Can you help me ?
    Thanks and regards
    - Abhilash


  • TO get both HTTP and HTTPS to work

    Aleksey Fomichenko says:
    - Add new webHttpBinding and set its security mode to "None"

    I tried this:












    and it wouldn't work for either HTTPS or HTTP

    You have to do this:










    Just to clarify: and both HTTP and HTTPS will then both work :)

    Trial and error

  • Thanks, Solution worked for me too and saved some time.

  • I am getting following error when i click on any of the services
    Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http].
    any idea on how to fix this?

  • Hi

    Very thankful. I was hanging from last 16 hours. Now fixed when i used security mode = "transport". After that i got other errors but those were quite simple to fix.

    Thanks a lot!

  • Big thanks to Tim B. I was using webHttpBinding and having SOAP based errors. After reading the comments I changes to basic http with Transport mode everything works like charm



    [ Friday, April 24, 2009 12:33 PM by Tim B.

    Such a beautiful article.

    Just one note: after 3 hours we realized that webHttpBinding is not suitable for regular SOAP-based clients (one has to watch these bindings :) and we acknowledge that this is ASP.NET-centric blog). We switched webHttpBinding to basicHttpBinding and our SOAP-based clients were able to parse the generated WSDL and to consume the web service.

  • Thanks so much, this quickly got me out of a jam!

  • thanks! helped a bunch

  • Thanks so much!!! tried different solution but your worked well.

  • Microsoft... please rethink and rewrite all this mess.

  • may allah bless you with 1000 virgins!!!!

    seriously, thanks for the posting. saved my arse big time and i agree with a former poster about microsoft's obtuse method of handling this process. very cumbersome.

  • Ah that pesky Transport mode (or at least it is when I forget to add it). Thank you and makes sense. This is what handles the SSL security for the binding and omitting it certainly would cause an error.

  • I love you man. save my life

  • Thanks, this saved me a couple of hours of work!

  • Thank you so much! You saved my time.

  • After 4 years of "Thank you"s - I'd like to add mine. You have saved me a lot of time.

  • Add me to the "this saved me a ton of time" list. WCF configuration is a never-ending mystery. Thanks for clearing this one up!

  • Another poor WCF ignorant soul saved, Thanks for this, you saved my day!

  • Thanks, worked like a charm for me...
    it saved a lot of time as I spent one whole day trying to figure out the solution.

    Your solution saved me :)

    Thanks

  • If you would like to obtain a good deal from this post then
    you have to apply such techniques to your won webpage.

  • Ahaa, its nice dialogue on the topic of this post here at this weblog, I have read all that, so now me also commenting
    at this place.

  • Ahaa, its fastidious dialogue concerning this article at this
    place at this web site, I have read all that, so at this time me also commenting
    here.

  • Wow, incredible blog layout! How long have you been blogging for?

    you made blogging look easy. The overall look of your website is
    fantastic, as well as the content!

  • Hello, I believe your web site might be having web browser compatibility issues.

    When I take a look at your site in Safari, it looks fine however, if opening in I.
    E., it has some overlapping issues. I simply wanted to
    provide you with a quick heads up! Besides that, excellent blog!

  • of course like your website but you have to test the
    spelling on several of your posts. Several of them are rife with spelling
    problems and I to find it very bothersome to tell the truth
    however I'll surely come again again.

  • What i don't understood is if truth be told how you're not actually much
    more well-appreciated than you may be now. You're very intelligent. You understand thus significantly with regards to this topic, made me in my view consider it from a lot of varied angles. Its like women and men don't seem to be interested until it is something to accomplish
    with Woman gaga! Your personal stuffs outstanding. At all times deal with it
    up! It would be better if your character was left to go it alone.

    Nintendo 3DS was developed and primed to become the successor to the Nintendo DS.
    I rented it for a few days and thoroughly enjoyed playing it for a few hours a day, however if I were to buy this game I'd wait for the price to depreciate quite a ways before purchasing.

  • Asking questions are truly good thing if you are not understanding something fully, however this
    paragraph provides pleasant understanding even.

  • It's not my first time to pay a quick visit this web page, i am visiting this web site dailly and obtain good information from here all the time.

  • I every time spent my half an hour to read this webpage's articles or reviews everyday along with a mug of coffee.

  • you are truly a excellent webmaster. The website loading pace
    is incredible. It kind of feels that you're doing any distinctive trick. In addition, The contents are masterpiece. you've performed a fantastic task on this subject!

Comments have been disabled for this content.