none
Reflection problem please help RRS feed

  • Question

  • I want to use refelection technique to invoke proxy RFC call.

    I've generated assembly from the proxy. now i want to use this assembly via reflection technic, eeverything works fine, only problem is setting the credential.

     

    The class UserNamePassClient is sealed class. which has user name property.

    Please suggest me how can i set this credential.

     

    Code: I want to achieve the following using refelection:

     

    RfcClient rfcClient = new RfcClient(binding, address);

    rfcClient.ClientCredentials.UserName.UserName = "";

    rfcClient.ClientCredentials.UserName.Password = "";

     

    When use this code it gives me error

    Object is not of target type.

     

    MethodName = "RFC";

    MInfo = null;

    for (int i = 0; i < MI.Length; i++)

    {

    if (MIIdea.ToString() == MethodName)

    MInfo = MIIdea;

    }

    PI = MInfo.GetParameters();

    SAPBinding binding = new SAPBinding();

    binding.AcceptCredentialsInUri = true;

    // Create EndpointAddress

    EndpointAddress address = new EndpointAddress("sap://CLIENT=800;LANG=EN;@A/%2FH%2Fsaprouter.majul.com%2FH%2Fsapmai/00");

    //address.Uri = strUri;

    // create channel factory using channel shape IRequestChannel

    Type[] types = WSAssembly.GetTypes();

    Type t = types[4];

     

    Object []Params = {binding,address};

    ConstructorInfo []con = t.GetConstructors();

    ConstructorInfo conf = con[4];

    object objCon = conf.Invoke(Params);

    Type tp = objCon.GetType();

    PropertyInfo pi = tp.GetProperty("ClientCredentials");

    Type ti = pi.PropertyType;

    Type ti1 = ti.GetType();

    PropertyInfo pii = ti.GetProperty("UserName");

    Type tii = pii.PropertyType;

    Type tii1 = pii.GetType();

    //PropertyInfo piii = tii.GetProperty("UserName");

    //object[] strUser = { "student03" };

    MethodInfo piii = tii.GetMethod("set_UserName");

    object[] strUser = { "stuuud" };

    object[] p = new Object[0];

    Type typeNeste = (typeof(System.String));

    //piii.SetValue(typeNeste, strUser, null);

    piii.Invoke(tii, strUser); -- gives me error

    //InvokeMember("set_UserName", BindingFlags.Default | BindingFlags.InvokeMethod, null, tii, strUser); -- gives me error

    tp.InvokeMember("Open", BindingFlags.Default | BindingFlags.InvokeMethod, null, objCon, p);

     

     

    complete code

    ===============================

    Monday, March 17, 2008 2:24 PM