0

I have to generate XML string like below for SOAP request.

<soapenv:Body>
<user:getUserProfile>
     <user:getUserProfileInput>
        <requestorInfoDVO>
           <dvo:ApplicationName>?</dvo:ApplicationName>
           <!--Optional:-->
           <dvo:HostName>?</dvo:HostName>
           <!--Optional:-->
           <dvo:CorrelationId>?</dvo:CorrelationId>
        </requestorInfoDVO>
        <dvo1:getUserProfileInputDVO>
           <dvo1:effectiveDate>?</dvo1:effectiveDate>
           <dvo1:commissionLevelServiceInputDVO>
              <dvo1:UserCode>?</dvo1:UserCode>
              <dvo1:stateCode>?</dvo1:stateCode>
              <dvo1:marketCode>?</dvo1:marketCode>
              <dvo1:program>?</dvo1:program>
              <!--Optional:-->
              <dvo1:lob>?</dvo1:lob>
              <!--Optional:-->
              <dvo1:reportingOffice>?</dvo1:reportingOffice>
              <!--Optional:-->
              <dvo1:userTypeCd>?</dvo1:userTypeCd>
           </dvo1:commissionLevelServiceInputDVO>
        </dvo1:getUserProfileInputDVO>
     </user:getUserProfileInput>
  </user:getUserProfile>
</soapenv:Body>

I have used the below code request to get format in XML in string.

Below is my C# Code

var request = new getUserProfile
{
    getUserProfileInput = new getUserProfileInput
    {
        getUserProfileInputDVO = new GetUserProfileInputDVO
        {
            effectiveDate = DateTime.Now,
            commissionLevelServiceInputDVO = new CommissionLevelServiceInputDVO
            {
                marketCode = "test",
                program = "QQ",
                stateCode = "CT",
                UserCode = "A User"
            }
        },
        requestorInfoDVO = new RequestInfoDVO
        {
            ApplicationName = "TESTAPP",
            CorrelationId = Guid.NewGuid().ToString(),
            HostName = "LOCALHOST"
        }
    }
};

 XmlSerializer xmlSerializer = new XmlSerializer(request.GetType());
 string test = string.Empty;
 using (StringWriter textWriter = new StringWriter())
     {
         xmlSerializer.Serialize(textWriter, request);
         test = textWriter.ToString();
      }

But I am getting the below result.

<getUserProfile>
 <getUserProfileInput>
   <getUserProfileInputDVO>
    <effectiveDate>2018-02-15T18:44:31.9012149+05:30</effectiveDate>
  <commissionLevelServiceInputDVO>
    <marketCode>test</marketCode>
    <program>QQ</program>
    <stateCode>CT</stateCode>
    <UserCode>A User</UserCode>
  </commissionLevelServiceInputDVO>
</getUserProfileInputDVO>
<requestorInfoDVO>
  <ApplicationName>TESTAPP</ApplicationName>
  <CorrelationId>ca003779-3874-4933-8577-c03bc00670c5</CorrelationId>
  <HostName>LOCALHOST</HostName>
</requestorInfoDVO>

but I need the result with user: , dvo:, dvo:1 alias dynamically. So, what can i do in request to get the above type of XML? So, is there any way to get the result or any change i can do in my request with XML serialize ?

Nikunj WA
  • 45
  • 7

0 Answers0