I have to send Active Directory data to a third-party application. This third-party application provides a .WSDL URL which I have added as a Service Reference in my .NET application. After this I have to call a function "Import" which looks something like this:
Import(Security security, string Data, int FolderID)
Here 'Data' is the XML data that needs to be transferred. I have an XML something like this:
            var xEle = new XElement("Document",
                        from emp in lstADUsers
                        select new XElement("Record",
                                     new XElement("UserName", emp.UserName),
                                       new XAttribute("FirstName", "TEST_FNAME"),
                                       new XAttribute("LastName", "Test_LNAME"),
                                       new XAttribute("Email", "test@test.com")
                                   ));
I call the Import method as:
Import(token, xEle, 1)
When this method is hit, I am getting below error:
The top XML element 'Data' from namespace '' references distinct types System.String and System.Byte[]. Use XML attributes to specify another XML name or namespace for the element or types.
The third-party application expects SOAP data.
Extra details
SOAP envelope looks like this:
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:sec='http://schemas.xmlsoap.org/ws/2003/06/secext' xmlns:wsu='http://schemas.xmlsoap.org/ws/2003/06/utility' 
xmlns:urn='urn:TestApp'>
   <soapenv:Header>
      <sec:Security>
         <sec:UsernameToken wsu:Id='TestApp'>
            <sec:Username>TestUser</sec:Username>
            <!--Optional:-->
            <sec:Password>TestPassword</sec:Password>
         </sec:UsernameToken>
      </sec:Security>
   </soapenv:Header>
   <soapenv:Body>
     <urn:ImportData>
     <Table></Table>
         <FolderId>0</FolderId>
         <Data><![CDATA[<Document>
         <Record></Record>
</Document>
</Data>
Code Changes Below
 /// <summary>
/// Summary description for ThirdPArtyApp
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class ThirdParty : System.Web.Services.WebService
{
    public Header header;
    [WebMethod]
    [SoapHeader("header", Direction = SoapHeaderDirection.InOut)]
    public void CreateXmlForImport()
    {
   ThirdParty_Serv thirdParty = new ThirdParty_Serv();
        header.Username = "test123";
        header.Password = "XYZ123";
            const string FILENAME = @"D:\Users\Documents\test.xml";
            XDocument doc = XDocument.Load(FILENAME);
            XNamespace nsUrn = doc.Root.GetNamespaceOfPrefix("urn");
            XElement importData = doc.Descendants(nsUrn + "ImportData").FirstOrDefault();
            XElement xCdata = new XElement("Document",
                                    new XElement("Record",
                                     new XAttribute("UserName", "T12345"),
                                       new XAttribute("FirstName", "TEST_RP"),
                                       new XAttribute("LastName", "Test_LNAME"),
                                       new XAttribute("Email", "test@test.com")
                                   ));
        
            string cDataStr = xCdata.ToString();
            XCData cdata = new XCData(cDataStr);
            thirdParty.ImportData("/Do/Persons", 0, cDataStr, 3);
    }
}
 
    