C# Escaping XmlType Name with special char within

2019-09-14 19:53发布

问题:

i need to implement and SOAP Service without using the WSDL (because its broken and will not be fixed). Now im stuck at a point where i need to set type attributes for some classes (base classes and derived one)

normaly ill decorate my DTOs like this:

BaseClass:

[XmlInclude(typeof(Person))]
[XmlType("Partner", Namespace = "http://....")]
public abstract class Partner 
{...}

and the DerivedOne:

 [XmlType("Person")]
public class Person : Partner
{...}

the result looks like this:
<tar:Partner xsi:type="Person">

but now the API Document tells me to create a request like:

<tar:Partner xsi:type="par:CT_Person">

(tested in Fiddler and works) How is it possible to create a typeName set with a NameSpace Prefix (par) or set the name like:

[XmlType("par:CT_Person")]?

deactivate(override) the escaping functionallity is no option for me.

thanks in advance.

回答1:

after testing the whole day and trying around... right after writing my question i got the answer by my self.

when i set the namespace in my baseclass i can set a namespace in my derived one with a different URL. than it works...

hope this post will help someone else facing the problem :)