Gee Batol

Gee Batol

  • NA
  • 9
  • 14.4k

Using WCF Test Client and XML response question

Jan 12 2012 9:09 PM
Hello,
 
I need a bit of understanding on how my service contract and the resulting WCF response would affect the client app that would consume my WCF service. Below are the details that I have in my code. Can you help me with the questions below please?
 
1. In WCF's XML response, how do I change the element <ExtractListResult> to another name by using any XML attribute or WCF functionality?

2. In the same output, how do I change <FinalXmlEntity> into another name as well, without changing the Class name? I can see WCF is using the class name to come up with this element name.

3. Does specifying the XmlElement name attribute ONLY CHANGES THE output display, and not the underlying field/property when this service is consumed by the calling app? I'm checking the output by using the WCF Test Client only and seeing the XML response. Or is the XMLElement name the one to be seen by the calling app?
 
I've use XMLroot, CollectionsDataContract, and a bunch of other things to put on top of the FinalXmlEntity class to change it's XML element name in the output, but no success. The change in the data members' names have been successful though.
 
Thank you in advance.
 
 
SERVICE INTERFACE:
 
    [ServiceContract]
    [XmlSerializerFormat(Style = OperationFormatStyle.Document)]
    public interface IService1
    {
        [OperationContract]
        List<FinalXmlEntity> ExtractList();
 
    }
 
DATA CONTRACT:
 
[DataContract]
    public class ProgrammeList
    {
        [DataMember]
        public string EmpCode { get; set; }
 
        [XmlElement("Employee Link")]
        [DataMember]
        public string EmpLink { get; set; }
 
        [DataMember]
        public string RoleCode { get; set; }
 
        [XmlArray("EmploymentHistory"), XmlArrayItem("Company")]
        [DataMember]
        public List<string> EmploymentLink { get; set; }
    }
 
 
RETURNED LIST COLLECTION:
 
 [Serializable]
    public class FinalXmlEntity
    {
        public string EmpCode { get; set; }
 
        [XmlElement("Employee")]
        public string EmployeeLink { get; set; }
 
        public string RoleCode { get; set; }
 
        [XmlArray("EmploymentHistory"), XmlArrayItem("Company")]
        public List<string> EmploymentLink { get; set; }
 
        public FinalXmlEntity(string s1, string s2, string s3, List<string> ListComp)
        {
            EmpCode = s1;
            EmployeeLink = s2;
            RoleCode = s3;
            EmploymentLink = ListComp;
        }
        public FinalXmlEntity()
        {
        }
    }
 
WCF TEST CLIENT's  RESPONSE OUTPUT (in XML tab)
 
<s:Body u:Id="_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <ExtractListResponse xmlns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <ExtractListResult>
        <FinalXmlEntity>
          <EmpCode>ABC245</EmpCode>
          <Employee>John Michael Doe</Employee>
          <RoleCode>DD</RoleCode>
          <EmploymentHistory>
                  <Company>XYZ Digital Corporation</Company>
                  <Company>Multiply My Profit Inc.</Company>
                  <Company>Hirem and Firem Ltd.</Company>
          </EmploymentHistory>
        </FinalXmlEntity>
 ...
...
...