Web services: method cannot be reflected exception

11,154

I found a solution but I cannot explain why it is working. I simply removed all the type mapping attributes from all methods and I don't get any more errors.

Lines removed:

[XmlType(TypeName = "string", Namespace = "http://www.w3.org/2001/XMLSchema")]

If somebody can explain I would really appreciate it!

Share:
11,154
Krumelur
Author by

Krumelur

Freelancer, Xamarin Hacker. Computers (gaming and developing) have always been part of my life, starting with the famous C64 and moving on to the PC a few years later. For quite some time, an iPhone has been my companion. I'm excited about developing mobile applications, especially with Xamarin.

Updated on June 16, 2022

Comments

  • Krumelur
    Krumelur almost 2 years

    When trying to create an instance of a service, I'm getting a

    "Method cannot be reflected"

    exception. Digging deeper down in the inner exceptions reveals:

    "Types 'WebServiceClient.com.compamy.string1' and 'WebServiceClient.com.company.string' both use the XML type name, 'string', from namespace 'http://www.w3.org/2001/XMLSchema'. Use XML attributes to specify a unique XML name and/or namespace for the type."

    What does the damn thing want from me? It is code auto generated by VS2010...why do I have to fiddle with it?

    Here are the two types:

    [GeneratedCode( "System.Xml", "4.0.30319.233" )]
    [Serializable]
    [DebuggerStepThrough]
    [DesignerCategory("code")]
    [XmlType(TypeName = "string", Namespace = "http://www.w3.org/2001/XMLSchema")]
    [XmlRoot("FileName", Namespace = "http://company.com/api3/Content/Download/", IsNullable = true)]
    public partial class string1 : SoapHeader
    

    and

    [GeneratedCode("System.Xml", "4.0.30319.233" )]
    [Serializable]
    [DebuggerStepThrougt]
    [DesignerCategory("code")]
    [XmlTypeAttribute(Namespace = "http://www.w3.org/2001/XMLSchema")]
    [XmlRootAttribute("SessionKey", Namespace = "ns", IsNullable = true)]
    public partial class @string : SoapHeader
    
  • Marcus
    Marcus over 10 years
    Did you come to any solution on why this occurred, I have the same problem but with JSON.
  • Nawar Khoury
    Nawar Khoury over 8 years
    I had the same problem when I was calling a webservice that was written in java (not sure if that matters) from a C# client, also removed the type mapping attributes and it worked! can't really understand why!
  • user1040975
    user1040975 almost 7 years
    You kind of said why it doesn't work just by restating the error and you can see why in your attributes where your namespaces are different. The namespace expecting the object is expecting a string type, or at least when serialized the node will be "string". I had both the type and an error similar with that of your namespace. I had tried sending my xml with the "w3" like you were, then with an available soap library, and it finally worked when I referenced the url of the api where the wsdl is... if you used a wsdl to get your schema maybe give it a try