Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

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

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

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.

I got the same message but mine was caused by a missing System.Runtime.Serialization.dll since I tried to run a 3.5 application on a machine with only .NET 2.0 installed.

I had the same issue but I found that one of the WebMethod parameters has a member that is of type interface that is why VS could not serialise it. here is the exception when trying to download the disco file

System.InvalidOperationException: Cannot serialize member 'Leopard.JobDespatchParameters.SendingUser' of type 'Leopard.Interfaces.IUser', see inner exception for more details. ---> System.NotSupportedException: Cannot serialize member Leopard.JobDespatchParameters.SendingUser of type Leopard.Interfaces.IUser because it is an interface.

Old thread but I had a different issue, Maybe of help to someone. referenced dlls were mixed up between two versions on data layer and service layer that caused the problem.

Another scenario where this error can happen: I simply had another web method with the same name (but different parameters)in my web service that slipped in during a code merge. After I deleted the old method it worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top