none
Custom Binding Problem RRS feed

  • Question

  • Hi,

     

    I need to configure a custom clock skew value, at least that's what the exception is telling me, even though the client and server clocks match exactly!. I figured it would be easy to try out a customized maxClockSkew value but I was wrong. I understand I have to switch from a standard binding (currently wsHttpBinding) to a custom one on both the server and client.

     

    This is fine, but I can't figure out how to replicate some of the stuff I had set up in the original binding, such as reader quotas and what have you. Is there a tool that will do this conversion for me?

     

    Here is my current binding configuration on the client:

     

    <wsHttpBinding>

                <binding name="MyBinding" closeTimeout="00:01:00"

            openTimeout="00:01:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"

            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"

            maxBufferPoolSize="524288" maxReceivedMessageSize="100000000"

            messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"

            allowCookies="false">

                            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="100000000"

                maxBytesPerRead="4096" maxNameTableCharCount="16384" />

                            <reliableSession ordered="true" inactivityTimeout="00:10:00"

                enabled="false" />

                            <security mode="Message">

                                        <transport clientCredentialType="Windows" proxyCredentialType="None"

                    realm="" />

                                        <message clientCredentialType="UserName" negotiateServiceCredential="true"

                    algorithmSuite="Default" establishSecurityContext="true" />

                            </security>

                </binding>

    </wsHttpBinding>

     

    And here is my server one:

     

    <wsHttpBinding>

                <binding name="MyBinding" closeTimeout="00:01:00" openTimeout="00:01:00" sendTimeout="00:60:00" maxReceivedMessageSize="100000000" messageEncoding="Mtom">

                            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="100000000" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>

                            <security mode="Message">

                                        <message clientCredentialType="UserName"/>

                            </security>

                </binding>

    </wsHttpBinding>

     

     

    Incidentally, the exception only occurs if the server takes around 20 minutes to execute. If it takes around 10 minutes everything works fine. I'm not sure why 20 is the magic number that makes it fall over, considering the skew is set to 5. I'm not even sure why the skew exception is being throw in the first place.

     

    If anyone has any insight that'd be great.

     

    Thanks

    Monday, April 2, 2007 11:12 PM

Answers

  • I don't know the answer to your question about why the clock-skew stuff is happening.

     

    But I can tell you how to convert an existing coded/config'd binding into the corresponding config for a CustomBinding.  The sample code below shows the essential part.  Basically, you can start from a binding in code (or from config, e.g. with
            new WSHttpBinding("MyBinding");  // load "MyBinding" config

    ) and then twiddle whatever knobs, and/or convert it to a CustomBinding via code like this.  Then the major block of code below will generate the corresponding config for you.

     

    Code Snippet

    using System;

    using System.ServiceModel;

    using System.ServiceModel.Description;

    using System.ServiceModel.Channels;

    using System.ServiceModel.Configuration;

    using System.Configuration;

     

    public class DemoHowToConvertBindingInCodeToAConfigFile

    {

        public static void Main()

        {

            BasicHttpBinding binding = new BasicHttpBinding();

            binding.SendTimeout = TimeSpan.FromSeconds(22);

            binding.Security.Mode = BasicHttpSecurityMode.Message;

            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;

            CustomBinding custom = new CustomBinding(binding);

     

            Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();

            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = "out.config";

            fileMap.MachineConfigFilename = machineConfig.FilePath;

            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            config.NamespaceDeclared = true;

            ServiceContractGenerator scg = new ServiceContractGenerator(config);

            string sectionName, configName;

            scg.GenerateBinding(custom, out sectionName, out configName);

            config.Save();

        }

    }

     

     

    Tuesday, April 3, 2007 12:37 AM
  • Hmm, appears to be a bug in ServiceContractGenerator, I had not noticed.  (I filed a bug.)

     

    In the meantime, you can just manually specify the timeout values my modifying the config file by hand.  For example

                <customBinding>
                    <binding name="yaddaYadda" sendTimeout="00:03:00">
     

    Wednesday, April 4, 2007 9:26 AM

All replies

  • I don't know the answer to your question about why the clock-skew stuff is happening.

     

    But I can tell you how to convert an existing coded/config'd binding into the corresponding config for a CustomBinding.  The sample code below shows the essential part.  Basically, you can start from a binding in code (or from config, e.g. with
            new WSHttpBinding("MyBinding");  // load "MyBinding" config

    ) and then twiddle whatever knobs, and/or convert it to a CustomBinding via code like this.  Then the major block of code below will generate the corresponding config for you.

     

    Code Snippet

    using System;

    using System.ServiceModel;

    using System.ServiceModel.Description;

    using System.ServiceModel.Channels;

    using System.ServiceModel.Configuration;

    using System.Configuration;

     

    public class DemoHowToConvertBindingInCodeToAConfigFile

    {

        public static void Main()

        {

            BasicHttpBinding binding = new BasicHttpBinding();

            binding.SendTimeout = TimeSpan.FromSeconds(22);

            binding.Security.Mode = BasicHttpSecurityMode.Message;

            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;

            CustomBinding custom = new CustomBinding(binding);

     

            Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();

            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = "out.config";

            fileMap.MachineConfigFilename = machineConfig.FilePath;

            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            config.NamespaceDeclared = true;

            ServiceContractGenerator scg = new ServiceContractGenerator(config);

            string sectionName, configName;

            scg.GenerateBinding(custom, out sectionName, out configName);

            config.Save();

        }

    }

     

     

    Tuesday, April 3, 2007 12:37 AM
  • (James posted my original message for me because I couldn't log in via IE. I have since figured out that I can log in via Firefox and am awaiting feedback as to why)

    Thanks for your help Brian - that certainly got me more than started. I thought I was all good until today I hit a timeout issue. It seems that setting Binding.XxxTimeout is useless when generating config. ie. No matter what you set these timeout values to, the generated config does not change to reflect these settings.

    Do you know how timeout values specified against standard bindings are manifested in custom bindings? Even if I set these values directly against the CustomBinding instance nothing is produced in the configuration.

    Here is the exception message (we only get the exception if the service takes a long time to respond. Hence, it must be a timeout issue):

    The message could not be processed. This is most likely because the action 'http://tempuri.org/Xxx' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

    Thanks for any help,
    Kent Boogaart
    Wednesday, April 4, 2007 6:14 AM
  • Hmm, appears to be a bug in ServiceContractGenerator, I had not noticed.  (I filed a bug.)

     

    In the meantime, you can just manually specify the timeout values my modifying the config file by hand.  For example

                <customBinding>
                    <binding name="yaddaYadda" sendTimeout="00:03:00">
     

    Wednesday, April 4, 2007 9:26 AM
  • Sorry Brian - that seems completely freaking obvious now that you point it out. I forgot there was a <binding/> inside the <customBinding/>.

    Thanks for your help and for reporting that bug.

    Cheers,
    Kent
    Thursday, April 5, 2007 1:34 AM