简体   繁体   中英

How to get rid default xml namespace if I one to serialize an object in wcf using datacontact

Here is my interface

[ServiceContract(Namespace = "")]      
interface IParam     {     } 

Here is my class

public class Parameter : IParam
{

    private string categoryName;

    [DataMember]
    public string CategoryName
    {
        get { return categoryName; }
        set { categoryName = value; }
    }


}

My operation contact is

[OperationContract]
string GetSegmentsByCategoryName(Parameter Params);

Here is my main:

Parameter abc = new Parameter ();
abc.CategoryName = "xxx";

str = client.Channel.GetSegmentsByCategoryName(abc);

when I check at wireshark i got this xml

<Params xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CategoryName>
xxx
</CategoryName>
</Params>

i one to get rid of xmlns:i="http://www.w3.org/2001/XMLSchema-instance when I pass the object through wcf httpbinding.

That isn't the default/element namespace, though - it is simply an unused alias to a namespace that might be used. It isn't actually breaking anything. I would strongly advise to simply leave it alone.

If you really, really wanted to do this - perhaps write a message inspector .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM