如何在WCF上手动更改xml响应?

时间:2018-02-19 07:09:21

标签: c# xml wcf

我的代码在WCF上是这样的:

public class Service1 : IService1
    {

        public REsponse getBarStores()
        {
            REsponse respons = new REsponse();
            respons.StokBarcode = new StoreCount();
            respons.StokBarcode.count = "123";
            respons.StokBarcode.stCode = new StoreCode();
            respons.StokBarcode.stCode.Add("asdasd");
            respons.StokBarcode.stCode.Add("qweqweqwe");

            return respons;

        }


}

   [MessageContract(IsWrapped = false, WrapperNamespace = "")]
    public class REsponse
    {
        [MessageBodyMember(Name = "getOrderResponse", Namespace = "")]
        public StoreCount StokBarcode { get; set; }
    }


    [DataContract(Namespace="")]
    public class StoreCount
    {
        [DataMember(Name="StoreCount")]
        public string count { get; set; }
        [DataMember(Name="StoreCode")]
        public StoreCode stCode { get; set; }
    }

    [CollectionDataContract(ItemName = "StoreCode", Namespace = "")]
    public class StoreCode : Collection<string>
    {


    }

我的输出xml像this.it一样带有集合名称,但我不想这样:

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

      <StoreCount>76</StoreCount>

      <StoreCode>
         <StoreCode>517</StoreCode>
         <StoreCode>531</StoreCode>
         <StoreCode>541</StoreCode>
         <StoreCode>558</StoreCode>
         <StoreCode>562</StoreCode>
         <StoreCode>568</StoreCode>
      </StoreCode>

    </ getBarStoresResponse >

我的问题xml这样的输出如何在WCF上执行此xml响应?我不想在WCF上看到xml响应的集合名称。我怎么能做这个结构xml:

<getBarStoresResponse>
<StoreCount>76</StoreCount>
         <StoreCode>517</StoreCode>
         <StoreCode>531</StoreCode>
         <StoreCode>541</StoreCode>
         <StoreCode>558</StoreCode>
         <StoreCode>562</StoreCode>
         <StoreCode>568</StoreCode>
</getBarStoresResponse>

0 个答案:

没有答案