locked
Problem with wsHttpBinding RRS feed

  • Question

  • After reading more about wshttpbinding, I just can't get it to work. No matter what I try, I keep getting the below error message (with security mode commented out). I understand why because of the different SOAP versions between bindings.

    "(415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'"

    I read more about the TransportWithMessageCredentials at the following link:

    http://msdn.microsoft.com/en-us/library/ms789011.aspx

    but still could not get it to work.

    I can use basicHttpBinding just fine for internal apps and works great (if I don't include any transactions), but my application in the WCF layer still needs to support transactions (see below), from which I understand that basicHttpBinding doesn't support, because it doesn't contain the transactionflow attribute.

    [OperationContract]

    [TransactionFlow(TransactionFlowOption.Allowed)]

    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))

    When I try and run the below with the security mode included, the svc config editor doesn't even start up and throws the following error: "System.InvalidOperationException: Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http]."

    I know it's expecting some kind of SSL/https security, but my website (as you can see below is http) . That would be fine for the public facing websites, but for internal sites, for now, all I want to do is have support for transactions.

    Here is my server side setup for wsHttpBinding:

    <bindings> 
          <wsHttpBinding> 
            <binding name="WsHttpBinding_IYeagerTechWcfService" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="24.20:31:23.6470000" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transactionFlow="true"> 
              <security mode="Transport" > 
                <transport clientCredentialType = "Windows" /> 
              </security> 
            </binding> 
          </wsHttpBinding> 
    </bindings>
    <?xml version="1.0"?> 
    <services> 
      <clear /> 
     
      <service name="YeagerTechWcfService.YeagerTechWcfService"> 
        <endpoint address="" binding="wsHttpBinding" contract="YeagerTechWcfService.IYeagerTechWcfService" > 
          <identity> 
            <dns value="localhost" /> 
          </identity> 
        </endpoint> 
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
        <host> 
          <baseAddresses> 
            <add baseAddress="http://abc.com/yeagerte/YeagerTechWcfService.YeagerTechWcfService.svc" /> 
          </baseAddresses> 
        </host> 
      </service> 
    </services>

    Here is my client side setup:

    <?xml version="1.0"?> 
    <client> 
      <endpoint address="http://abc.com/yeagerte/YeagerTechWcfService.YeagerTechWcfService.svc" 
        binding="wsHttpBinding" contract="YeagerTechWcfService.IYeagerTechWcfService" 
        name="WsHttpBinding_IYeagerTechWcfService" /> 
    </client>

    Could somebody please provide the following:

    Is there another way to support transactions in WCF for basicHttpBinding or any other way for that matter?

    If so, how do I implement it?

    If not, what are my options?

    For the above question, I may have figured out an answer but want to run it by somebody more experienced in this matter.

    Instead of having the WCF layer handle the transactions (like mentioned above), I propose I use basicHttpBinding and the following code in my Controller when it passes the data to the WCF layer:

    // method here

    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) 
                            { 
                                db.EditCategory(cat); 
                               // the above code would execute the EditCategory method below in the WCF layer  and keep the transaction alive                       
                                ts.Complete(); 
                                ts.Dispose(); 
                            } 
                            return Json(new GridModel(db.GetCategories()));
    // end method

    WCF layer:

    public void EditCategory(Category cat) 
            { 
                try 
                { 
                  using (YeagerTechEntities DbContext = new YeagerTechEntities()) 
                    { 
                        Category category = new Category(); 
     
                        category.CategoryID = cat.CategoryID; 
                        category.Description = cat.Description; 
     
                            // do another db update here or in another method... 
     
                        DbContext.Entry(category).State = EntityState.Modified; 
                        DbContext.SaveChanges(); 
                    } 
                 } 
     
                catch (Exception ex) 
                { 
                    throw ex; 
                } 
            }

    For public facing websites using SSL, how do I properly implement wsHttpBinding? 


    Bill Yeager

    Tuesday, September 4, 2012 11:13 PM

All replies

  • fyi, I tried what I said about the option with using the transactionscope in the Controller and it worked fine with basicHttpBinding.

    Any other feedback about this and or the other questions about my previous post would be appreciated.


    Bill Yeager

    Wednesday, September 5, 2012 12:26 AM
  • Hi,

    ->When I try and run the below with the security mode included, the svc config editor doesn't even start up and throws the following error: "System.InvalidOperationException: Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http]."

    If you enabled Transport Security by set Security mode to Transport or TransportWithMessageCredentials, it is required that the host support SSL. In your case, you can add a https binding with a self-signed certificate on the website to register a https schema.

    Thanks.


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 6, 2012 5:19 AM
  • Leo, that explanation is about as much as a straightforward one I've gotten to date! Thaks for clearing it up.

    In regards to you comment:

    you can add a https binding with a self-signed certificate on the website to register a https schema

    How would I go about doing the above?

    If you could also provide a sample of the security node in the bindings, I'd really appreciate that too.


    Bill Yeager

    Thursday, September 6, 2012 2:04 PM
  • Hi Bill,

    I assumed that you host WCF service in IIS, you can follow the article below to enable SSL support by using IIS Manager.

    How to Set Up SSL on IIS 7
    http://www.iis.net/learn/manage/configuring-security/how-to-set-up-ssl-on-iis

    If you self-host WCF service, you can create a self-host certificate by using MakeCert tool and bind the SSL certificate to specified port number by using HttpCfg or netsh(Windows Vista and later version).

    Makecert.exe (Certificate Creation Tool)
    http://msdn.microsoft.com/en-US/library/bfsktky3(v=vs.100).aspx

    How to: Configure a Port with an SSL Certificate
    http://msdn.microsoft.com/en-us/library/ms733791(v=vs.100).aspx

    The binding you posted should works well, if you encounter any problem, please update here.


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Edited by LeoTang Friday, September 7, 2012 7:42 AM
    Friday, September 7, 2012 7:41 AM
  • Thanks a lot Leo. I will follow your instructions....

    One thing...

    If I set up SSL for the site that I have now, and use wsHttpBinding with it, will I still be able to do the following:

    Switch over and use basicHttpBinding that won't require a cert and run under http mode instead of https. Or, after setting up the site to run under SSL, is that permanet where I can't switch back?

    The point being is that I am able to test both bindings under SSL and without SSL with the same website?

    I'll wait on setting up the site with the SSL until I here back from you and possibly what to do.

    Thanks so much for your help.


    Bill Yeager

    Friday, September 7, 2012 12:43 PM
  • Another option Leo is if it's possible to run the website under wsHttpBinding with security (as you described before) or without security...

    As I'm writing this, I don't think that's possible because in order to run wsHttpBinding, you have to run it with some kind of security. So, in that case, if this is true, if you can still answer my previous question, it would be much appreciated...

     

    Bill Yeager

    Friday, September 7, 2012 2:33 PM