开发者

Convert Data trasfer objects to XmlElement

I have a Dataobject that look like this

namespace WCFDemo
{
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class pricinginput
    {
        /// <remarks/>
        public aRequest request;
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class aRequest
    {   
        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string input1;

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string input2;

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string input3;
    }
}

and Service Operation like

public string pricinginput(pricinginput sourceValue)
{
    return string.Format("You entered: {0}", 2323);
}

to call the service i have to do

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://Server/Service" xmlns:wcf="http://schemas.datacontract.org/2004/07/WCFDemo">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:pricinginput>
         <!--Optional:-->
         <ser:sourceValue>
            <wcf:request>
               <wcf:input1>?</wcf:input1>
               <wcf:input2>?</wcf:input2>
               <wcf:input3>?</wcf:input3>
            </wcf:request>
         </ser:sourceValue>
      </ser:pricinginput>
   </soapenv:Body>
</soapenv:Envelop开发者_如何学Goe>

How to have convert the sourcevalue into a xmlelemet that looks like belwo , my datacontext already defines the data element as attribute for input1, inptu2 ...

<pricinginput>
    <sourcevalue>
                <request    input1="" input2="" input3=""/>
            <sourcevalue>
</pricinginput>


How about this: you might develop a serializer by yourself and then serialize the object into your customized xml format?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜