locked
Consume soaprequest RRS feed

  • Question

  • User-148788041 posted

    Hi<br>
    I have asmx url like https://test.aspx?wsdl ,method name, arguments as object array.<br>
    Can I write<br>
    Methodinfo mi=was .Gettype().Get method(method name )<br>
    Var result=mi.invoke(classinstance,parameter as object array)<br>
    <br>
    Wednesday, January 30, 2019 12:49 PM

All replies

  • User-893317190 posted

    Hi Guhananth,

    Do you mean you want to call the asmx using reflection?

    If so, you could.

    Below is my test sample.

               MyServiceSoapClient client = (MyServiceSoapClient) 
                Activator.CreateInstance(typeof(MyServiceSoapClient)); // use reflection to create client instance 
              MethodInfo info=  typeof(MyServiceSoapClient).GetMethod("HelloWorld");  // get method info of method HelloWorld
              string result =(string) info.Invoke(client, new object[] { "my test parameter" });   // invoke the method
               Response.Write(result);  // output the result

    My Service

     [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class MyService : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string HelloWorld(string arg)
            {
                return arg;
            }
        }

    The result.

    Best regards,

    Ackerly Xu

    Thursday, January 31, 2019 1:45 AM
  • User-148788041 posted

    Ackerly 

    Looks good . what is . i want to convert to datatable . and then convert to object

    MyServiceSoapClient is this asmx url ? like https://test/wsdl?
    Thursday, January 31, 2019 2:02 AM
  • User-893317190 posted

    Hi Guhananth,

    Not know clearly what you mean , but if you want to pass datatable to your MethodInfo as parameter, you don't need to do any convertion, just pass your datatable to the object array.

    If this is not your case , could you specify your problem or post the code you have tried and show us what problem you have met?

    Datatable should have no difference from string when calling web method.

    https://stackoverflow.com/questions/4966189/can-we-pass-dataset-to-a-web-service-method-if-yes-then-how

    Best regards,

    Ackerly Xu

    Thursday, January 31, 2019 9:30 AM
  • User-148788041 posted

    hi

    In your code where it is mentioned 

    MyServiceSoapClient
    Friday, February 1, 2019 1:38 AM
  • User-893317190 posted

    Hi Guhananth,

    It is generated by visual studio after I add service reference to  the asmx.

    Right click your asmx, click view in browser.

    The following  page should appear.

    copy its address, and right click your project's references , click add service reference, paste the address into the wizard's address bar.

    Click ok. The client should generated.Look for it in your project's connected services.

    Click it to find your client. It usually ends with Client.

    Best regards,

    Ackerly Xu

    Friday, February 1, 2019 2:59 AM