简体   繁体   中英

remove namespace's prefix in datacontract

My problem is the following :

I'm creating a SOAP service using WCF and I'm testing it using a chrome plugin called Boomerang SOAP & Rest Client (it create a request by loading your wsdl, you just have to change values).

But everytime my datamembers have namespace's prefix and i don't want them.

the request should look like this :

在此输入图像描述

And i get this :

在此输入图像描述

here is my service :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.Text;
using Ory_Soap.DTO;

namespace Ory_Soap
{

    [ServiceContract (Namespace = "http://my.company.com")]
    [XmlSerializerFormat]
    public interface FeedbackReceiverSOAP {

        [OperationContract]
        [WebInvoke]
        void receiveProvisioningFeedback(ProvisioningFeedback provisioningFeedback);


    }



    [DataContract(Namespace = "http://my.company.com")]
    public class ProvisioningFeedback
    {
        [DataMember(Name="header")]
        public Header header { get; set; }

        [DataMember(Name = "simIdentity")]
        public SimIdentity simIdentity { get; set; }

        [DataMember(Name = "responseStatus")]
        public ResponseStatus responseStatus { get; set; }

        [DataMember(Name = "parameters")]
        public List<Parameter> parameters { get; set; }

        [DataMember(Name = "options")]
        public List<Option> options { get; set; }
    }

}

I already tried to set an empty namespace on my DataContract but it didn't work. I'm pretty sure that my names attributes in Datamembers are optionnal here but I desperately tried this.

Can you help me resolve this please ?

Many thanks !

Your DataContract attribute specifies a namespace value " http://my.company.com " and so the xml you get is correct. If you want the datamembers to be in a different (empty) namespace, you could try [DataContract(Namespace = "")]. But I think that the xml you show as what you want it to look is not possible. The child elements do not inherit their parents namespace by default. You could have them inherit their parents default namespace. You xml would then have to look like this:

<root xmlns:blah="...">
  <element1 xmlns="whatever">
    <element2/>
  </element1>
</root>

element2 now inherits element1 's namespace

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