WCF SOAP - 从子节点中删除命名空间

时间:2016-12-22 20:53:30

标签: xml wcf soap

我正在构建一个服务,并且有一个客户端需要我在soap服务中尝试接收的特定格式的xml。我遇到的问题是,当我需要它只在根节点上时,名称空间前缀应用于子节点。下面是在soapui中为请求生成的soap信封:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:contact.com">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:ContactNotification>
         <!--Optional:-->
         <urn:Identifier>
            <!--Optional:-->
            <ID>122</ID>
         </urn:Identifier>
         <!--Optional:-->
         <urn:Details>
            <!--Optional:-->
            <ContactPerson>c</ContactPerson>
         </urn:Details>
      </urn:ContactNotification>
   </soapenv:Body>
</soapenv:Envelope>

我需要在&lt;上保留前缀urn:ContactNotification&gt; 但是从&lt;中删除它urn:标识符&gt; &lt; urn:详细信息&gt; 所以信封应如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:contact.com">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:ContactNotification>
         <!--Optional:-->
         <Identifier>
            <!--Optional:-->
            <ID>122</ID>
         </Identifier>
         <!--Optional:-->
         <Details>
            <!--Optional:-->
            <ContactPerson>c</ContactPerson>
         </Details>
      </urn:ContactNotification>
   </soapenv:Body>
</soapenv:Envelope>

我需要在WCF中使用XML Serializer来支持xml属性(上面的示例是缩减版本)

以下是我的课程代码:

using System.ServiceModel;
[System.Xml.Serialization.XmlTypeAttribute (Namespace="")]


public partial class Identifier
{

    private string idField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Namespace="")]
    public string ID
    {
        get
        {
            return this.idField;
        }
        set
        {
            this.idField = value;
        }
    }
}


using System.ServiceModel;

[System.Xml.Serialization.XmlType(Namespace ="")]

public partial class Details
{
    private string contactPersonField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Namespace="")]
    public string ContactPerson
    {
        get
        {
            return this.contactPersonField;
        }
        set
        {
            this.contactPersonField = value;
        }
    }
}

这些是我的服务接口/实现:

using System.Web.Configuration;
using System.Xml.Serialization;

namespace ContactService
{   
    [ServiceContract(Namespace = "urn:contact.com")]
    [XmlSerializerFormat]

    public interface IContactService
    {
        [OperationContract]
        [XmlSerializerFormat]
        void ContactNotification( Identifier Identifier, Details Details);
    }
}

using System.ServiceModel;
using System.Web.Configuration;
using System.Xml;
using System.Xml.Serialization;

namespace ContactService
{
    [ServiceBehavior(Namespace= "urn:contact.com")]
    [XmlSerializerFormat]
    public class ContactService : IContactService
    {
        [OperationBehavior]
        public void ContactNotification(Identifier Identifer, Details Details)
        {

        }
    }

已经找到了但却找不到解决办法。

0 个答案:

没有答案