Problems registering SoapExtension programmatically.... Help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fcaico@gmail.com

    #1

    Problems registering SoapExtension programmatically.... Help!

    I have a .NET 1.1 C# application that needs to connect to a custom web
    service for authentication and system access. This web service uses a
    custom SOAP header for security purposes.

    In the past this has been a non issue because I simply registered a
    SoapHeaderExten sion in the application's App.Config file.

    Now, however, we have need of using this C# client code in an assembly
    which doesn't have access to an app.config file (long story). So I
    wanted to be able to register this SoapHeaderExten sion
    programmaticall y at runtime.

    I found this reference: http://weblogs.asp.net/cweyer/archiv.../07/22929.aspx
    which tells how to do it, but this code isn't working for me at all.

    Basically in my code I use:

    protected void InjectSoapExten sions()
    {
    Assembly assBase;
    Type webServiceConfi g;
    object currentProp;
    PropertyInfo propInfo;
    object[] value;
    Type myType;
    object[] objArray;
    object myObj;
    FieldInfo myField;

    try
    {
    assBase = typeof(SoapExte nsionAttribute) .Assembly;

    webServiceConfi g = assBase.GetType (
    "System.Web.Ser vices.Configura tion.WebService sConfiguration" );

    if (webServiceConf ig == null)
    {
    throw new Exception("Unab le to get Web Service Config assembly");
    }

    *** currentProp =
    webServiceConfi g.GetProperty(" Current").GetVa lue(null, null);
    propInfo = webServiceConfi g.GetProperty(" SoapExtensionTy pes");
    value = (object[])propInfo.GetVa lue(currentProp , null);
    myType = value.GetType() .GetElementType ();
    objArray = (object[])Array.CreateIn stance(myType,
    (int)value.Leng th + 1);

    Array.Copy(valu e, objArray, (int)value.Leng th);

    myObj = Activator.Creat eInstance(myTyp e);
    myField = myType.GetField ("Type");

    myField.SetValu e(myObj, typeof(PediHead erExtension));
    objArray[(int)objArray.L ength - 1] = myObj;
    propInfo.SetVal ue(currentProp, objArray, null);
    }
    catch (Exception ex)
    {
    throw ex;
    }

    }

    The code fails at the assignment to currentProp because the retrieved
    type "webServiceConf ig" has no current or SoapExtension properties (in
    fact it has NO properties - I wrote a program to reflect through the
    type and its pretty bare).

    Any ideas? I'm getting pretty desperate here.

    Thanks

    Frank

Working...