WSE Time Tolerance in seconds a programmatic approach.

For some reason Microsoft thought it would be a good idea to only let us control the time tolerance in WSE 2.0 and 3.0 via the app.config file. ie

<configuration>
  <configSections>
    <section name="microsoft.web.services2" type="Microsoft.Web.Services2.Configuration.WebServicesConfiguration, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <microsoft.web.services2>
    <security>  
      <timeToleranceInSeconds>86400</timeToleranceInSeconds>  
    </security>    
   <diagnostics/>
   </microsoft.web.services2>
</configuration>
 
This isn't always a practical option.  In this case I have a DLL that needs to make a WSE web service call.  Its not realistic for all my clients to add this information to their app.config files.  And I am far to lazy to document it.
So enter reflection, We need to add a few lines of code to our  WSE web service inherited classes constructor.
public class MyWebServicWse : Microsoft.Web.Services2.WebServicesClientProtocol
{
    public  MyWebServicWse()
    {
        Type.GetType( "Microsoft.Web.Services2.Security.Configuration.SecurityConfiguration, Microsoft.Web.Services2, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", true, true )
        .GetField( "_timeToleranceInSeconds", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic )
        .SetValue( null, TimeSpan.FromSeconds((double) 86400) ); //86400 == a 24 hour time span.
    }
}
Comments [0]