Method 'XYZ' cannot be reflected

25,397

Solution 1

It seems the problem is down to data type issues between VS and the web service that was written in Java.

Ultimately it was fixed by manually editing the class and schema files that were created by VS.

Solution 2

I ran into the same problem earlier today. The reason was - the class generated by Visual Studio and passed as a parameter into one of the methods did not have a default parameterless constructor. Once I have added it, the error had gone.

Solution 3

I have come across the exact same problem when I was consuming a 3rd party web service. The problem in this instance was that the mustUndertand property in the reference file was looking for a Boolean, whereby the namespace property looked for a string.

By looking through the reference i was able to idenitfy the offending property and simply add "overrides" to the method signature.

Not ideal as any time you update the service you have to do this but I couldn't find any other way around this.

To find the reference file select "all files" from the solution explorer

Hope this helps

Solution 4

I'm guessing the wsdl emitted by or supplied with the service is not in a form that wsdl.exe or serviceutil can understand - can you post the wsdl or link to it?

how are you creating the proxy classes?

Also you might like to try and validate the wsdl against the wsdl schema to check its valid

Solution 5

In my case I was getting a "method cannot be reflected" error due to that fact that in the class being returned by method, I had failed to expose a default parameter-less constructor.

I was working in VB.NET. In my return class I had declared a "New(..)" method that took a couple parameters (because that is how I wanted to use it in my code). But by doing so, I had supressed the default (hidden) parameterless New() constructor that VB adds behind the scenes. Apparently the web service handler requires that a parameterless constructor be available. As soon as I added back into my class a parameterless New() constructor, it all worked fine.

Share:
25,397
Andy Rose
Author by

Andy Rose

Web developer that started with ASP 3.0 and moved onto ASP.NET. Currently dabbling with ASP.NET MVC and trying to get a better understanding of CSS and jQuery.

Updated on July 23, 2020

Comments

  • Andy Rose
    Andy Rose almost 4 years

    We have consumed a third party web service and are trying to invoke it from an ASP.NET web application. However when I instantiate the web service the following System.InvalidOperationException exception is thrown:

    Method 'ABC.XYZ' can not be reflected. System.InvalidOperationException: Method 'ABC.XYZ' can not be reflected. ---> System.InvalidOperationException: The XML element 'MyDoc' from namespace 'http://mysoftware.com/ns' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.

    From what I can gather there appears to be some ambiguity between a method and a type in the web service. Can anyone clarify the probably cause of this exception and is there anything I can do to rectify this or should I just go to the web service owners to rectify?

    Edit: Visual Studio 2008 has created the proxy class. Unfortunately I can't provide a link to the wsdl as it is a web service for a locally installed thrid party app.

  • AaA
    AaA over 9 years
    You marked this as answer but actually forget to mention how you solved it?
  • Andy Rose
    Andy Rose over 9 years
    @BobSort sorry, way to long ago to remember exactly what I did, but it would have been along the lines of manually updating the proxy classes that VS has created to access the service to use data types that it was expecting.
  • AaA
    AaA over 9 years
    Actually I managed to fix it too, there was a property class generated with same name as webservice method. I renamed the class and it fixed
  • PhillyNJ
    PhillyNJ almost 9 years
    You saved me hours,,,,
  • Braydie
    Braydie over 7 years
    And balance has been restored -- I lost 5 hours before finding this post
  • Bonez024
    Bonez024 about 5 years
    I imagine you saved me quite a headache as well. I had added some partial classes based off of an .xsd and adding a default ctor did it. Thanks!