none
The expected XML node type was XmlDeclaration, but the actual type is Element. RRS feed

  • Question

  • Hello,

    I am new to EWS. I created a C# application which syncs contacts from a database to Exchange using EWS Managed API. This app works great on PCs which are connected to our physical network/domain. Now, I am trying to make it work for remote PCs (which are not directly connected to the domain). The AutoDiscover call returns an error "The expected XML node type was XmlDeclaration, but the actual type is Element." 

    Here is my code

    private ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    try 
    {
    	service.Credentials = new NetworkCredential("test.user", "password", "mycomp.com"); 
    	service.AutodiscoverUrl("test.user@mycomp.com", RedirectionCallback);
    }
    catch (System.Exception e)
    {
    	sErr = e.Message;
    }
    I have also tried using WebCredentials but I get the same error. Fiddler does not give my any useful information. Any idea what I am doing wrong? Your help is greatly appreciated.

    Thanks.
    Vishnu




    • Edited by Vishnugupt Monday, September 19, 2016 8:49 PM
    Monday, September 19, 2016 8:45 PM

All replies

  • I'd suggest you enable tracing https://msdn.microsoft.com/en-us/library/office/dd633676%28v=exchg.80%29.aspx and look at the responses that are coming back it looks like your getting an invalid response the Managed API can't deal with (eg maybe a response from a Proxy server that returns invalid data).

    Cheers
    Glen

     
    Tuesday, September 20, 2016 3:02 AM
  • Glen,

    I have been trying to enable tracing. My problem is that tracing works for PCs which are connected to the domain but does not work for PCs which are not connected to the domain - It looks like the tracing code is being ignored on non-domain PCs. 

    Here is my code:

    // Enable trace
    service.TraceListener = new TraceListener();
    // Optional flags to indicate the requests and responses to trace.
    service.TraceFlags = TraceFlags.EwsRequest | TraceFlags.EwsResponse;
    service.TraceEnabled = true;
    
    
    public class TraceListener : ITraceListener
        {
            #region ITraceListener Members
    
            public void Trace(string traceType, string traceMessage)
            {
                CreateXMLTextFile("", traceMessage.ToString());
            }
    
            #endregion
    
            private void CreateXMLTextFile(string fileName, string traceContent)
            {
                // Create a new XML file for the trace information.
                try
                {
                    fileName = "c:\\ews\\ewstrace";
                    // If the trace data is valid XML, create an XmlDocument object and save.
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(traceContent);
                    xmlDoc.Save(fileName + ".xml");
                }
                catch
                {
                    // If the trace data is not valid XML, save it as a text document.
                    System.IO.File.WriteAllText(fileName + ".txt", traceContent);
                }
            }
        }

    If I delete the c:\ews folder, I get a message saying path does not exist on domain PCs but not on non-domain PCs. Any idea what is wrong?

    Thanks.

    Vishnu

    Thursday, November 17, 2016 3:17 PM
  • Hello Glen,

    I was able to get tracing working. Here is the trace I get on the non domain PC:

    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2016-11-18 16:56:35Z">
    Starting SCP lookup for domainName='mycomp.com', root path=''
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2016-11-18 16:56:37Z">
    LDAP call failed, exception: System.Runtime.InteropServices.COMException (0x8007054B): The specified domain either does not exist or could not be contacted.
    
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.get_AdsObject()
       at System.DirectoryServices.PropertyValueCollection.PopulateList()
       at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
       at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
       at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetScpUrlList(String domainName, String ldapPath, Int32&amp; maxHops)
       at Microsoft.Exchange.WebServices.Autodiscover.DirectoryHelper.GetAutodiscoverScpUrlsForDomain(String domainName)
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2016-11-18 16:56:37Z">
    Trying to call Autodiscover for admin.user@mycomp.com on https://mycomp.com/autodiscover/autodiscover.xml.
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="1" Time="2016-11-18 16:56:37Z">
    POST /autodiscover/autodiscover.xml HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0847.030
    
    
    </Trace>
    <Trace Tag="AutodiscoverRequest" Tid="1" Time="2016-11-18 16:56:37Z" Version="15.00.0847.030">
      <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
        <Request>
          <EMailAddress>sesc@mycomp.com</EMailAddress>
          <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
        </Request>
      </Autodiscover>
    </Trace>
    <Trace Tag="AutodiscoverResponseHttpHeaders" Tid="1" Time="2016-11-18 16:56:37Z">
    HTTP/1.1 301 Moved Permanently
    Content-Length: 177
    Content-Type: text/html; charset=UTF-8
    Date: Fri, 18 Nov 2016 16:56:12 GMT
    Location: http://www.mycomp.com/autodiscover/autodiscover.xml
    Server: Microsoft-IIS/8.5
    
    
    </Trace>
    <Trace Tag="AutodiscoverResponse" Tid="1" Time="2016-11-18 16:56:37Z" Version="15.00.0847.030">
      <head>
        <title>Document Moved</title>
      </head>
      <body>
        <h1>Object Moved</h1>This document may be found <a HREF="http://www.mycomp.com/autodiscover/autodiscover.xml">here</a></body>
    </Trace>
    

    LDAP call failed, exception: System.Runtime.InteropServices.COMException (0x8007054B): The specified domain either does not exist or could not be contacted.

    Can you tell me how to fix it?

    Thanks.
    Vishnu

    Friday, November 18, 2016 9:18 PM
  • It looks like there is problems with the way you have Autodiscover configured https://msdn.microsoft.com/en-us/library/office/dn467392(v=exchg.150).aspx eg your getting a 301 response that is redirecting to itself. My suggestion would be you use https://testconnectivity.microsoft.com/ and you can the diagnose you autodiscover issue.

    Cheers
    Glen

    Monday, November 21, 2016 3:41 AM