locked
Method not found exception. RRS feed

  • Question

  • Hello and thanks for any help,

    I have two methods in a web service and i am using reflection to call those methods at run time in a separated .cs. The problem is when i call the second method named "RequestLicence" i get a "method not found exception" but those two methods in web service and separated .cs are very similar and i dont understand why one is working fine but second is not.

    Here is the methods in web service:

    1. "GetProduct" method:

    [WebMethod]
        public LYS.RegistryService.ProductResponse GetProduct(string productNo)
        {
          LYS.RegistryService.ProductResponse r = new            LYS.RegistryService.ProductResponse();
          return r;
        }

    2. "RequestLicence" method:

        [WebMethod]
        public LYS.RegistryService.ServiceResponse RequestLicence(LYS.BusinesObjects.Customer c, string productCode, bool isDemoLicence, bool isProductLicence)
        {
          LYS.RegistryService.ServiceResponse r = new LYS.RegistryService.ServiceResponse();
          return r;
        }

    Methods are returning objects that derived from same interface.And methods in seperate .cs to call web service methods.

    1. "GetProduct" method:

    public ServiceResponseBase GetProduct(string productCode)
          {
            object obj = _WebServiceAssembly.CreateInstance("RegisteryService");
            Type typ = obj.GetType();
            object o = typ.InvokeMember("GetProduct", System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] { productCode });
            return InstantiateObject<ProductResponse>(o);
          }

    2. "RequestLicence" method:

          public ServiceResponseBase RequestLicence(LYS.BusinesObjects.Customer c, string productCode, bool isDemoLicence, bool isProductLicence)
          {
            object obj = _WebServiceAssembly.CreateInstance("RegisteryService");
            Type typ = obj.GetType();
            object o = typ.InvokeMember("RequestLicence", System.Reflection.BindingFlags.InvokeMethod, null, obj, new object[] { c, productCode, isDemoLicence, isProductLicence });
            return InstantiateObject<ServiceResponse>(o);
          }

    As you can see those two methods are very similar but "GetProduct" is working fine but "RequestLicence" is throwing "method not found exception" at "typ.InvokeMember" line.

    So what am i doing wrong?


    • Moved by Lisa Zhu Wednesday, November 7, 2012 9:07 AM asmx web services related (From:Visual C# General)
    Tuesday, November 6, 2012 7:47 AM

All replies

  • Hi,

    I'm guessing the problem is somewhere in the class Customer. Is it referenced from the same assembly in both service and caller (i.e. is it really the same class)? Does it have the DataContract attribute set above it?

    By the way, if you're programming your caller with knowledge of the service, why not just reference the service?

    Perhaps the (inner) exception has more detailed information?

    Hope this helps


    Please mark the best replies as answers - Twitter: @rickvdbosch - Blog: http://bloggingabout.net/blogs/rick

    Tuesday, November 6, 2012 8:01 AM
  • First i thing the same way as you think. I though it is about the parameters of "RequestLicence" method becouse "GetProduct" method accepting a string parameter (a primitive type) but "RequestLicence" method accepting a  Customer object that is a custom class. I deleted the parameter Customer from RequestLicence method but still same error.

    The Customer class is in a strongly named .dll file named LYS.dll and both two projects reference same version of that assembly.But it does not have DataContract attribute.

    Tuesday, November 6, 2012 8:21 AM
  • The inner exception is null. BUt have a static member "_COMPlusExceptionCode = -532459699".

    • Edited by emrahtopcu Tuesday, November 6, 2012 9:52 AM
    Tuesday, November 6, 2012 9:00 AM
  • can you try to catch SoapException and see the "exception.Detail.InnerText" or "exception.Detail.OuterXml" ? it will give you more detail of the kind of exception happening with WSDL.

    catch (SoapException ex)
    {
            string str = ex.Detail.InnerText;
            string str1 = ex.Detail.OuterXml;
    }

    regards

    joon


    • Edited by Joon84 Tuesday, November 6, 2012 10:07 AM
    Tuesday, November 6, 2012 10:05 AM
  • ok i realized that when i remove Customer parameter from web service method it is working fine. Yes i know i wrote before that i am getting same error instead. I missed something i think.

    The real problem is Customer parameter. Because it is a complex type i find that i need a datacontract. But i dont know how to do that. I added DataContract and DataMember attributes but it did not worked. 

    Is anyone know how to do this?

    Tuesday, November 6, 2012 11:17 AM
  • Hi emrahtopcu,

    From your description, I ‘d like to move this post to  the most related forum.

    There are more  experts in this aspect, so you will get  better support and  may have more luck getting answers.

    Thanks for your understanding.

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 7, 2012 9:07 AM
  • Were you aware that you are using the legacy ASMX web service technology? It should not be used for new development if you have any choice.

    In ASMX, DataContract is not used. You should check to see whether the Customer class meets the requirements of the XML Serializer. Anything you want serialized must have public read/write properties, and it must be a public class with a public, parameterless constructor.

    Also, exactly where are you getting the exception, and exactly what does it say? Please post the full output of ex.ToString() after catching the exception.

    Finally, what version of .NET and Visual Studio are you using?


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects

    Friday, November 9, 2012 3:23 AM
    Moderator