7

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 
1
  • Why don't name it StringHeader : SoapHeader? Commented Feb 15, 2012 at 14:27

1 Answer 1

8

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!

Sign up to request clarification or add additional context in comments.

3 Comments

Did you come to any solution on why this occurred, I have the same problem but with JSON.
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!
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.