简体   繁体   中英

EWS Exchange Web service API AutodiscoverUrl exception

I get an error when I try to create an appointment:

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

This Exception occurs when I call AutodiscoverUrl .
I created a web service to do this.

[webMethod]
CreateAppointment()
{
    var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
    {
        Credentials = new WebCredentials("myAcount@gmail.com", "mypassowrd")
    };

    service.AutodiscoverUrl("myAcount@gmail.com");

    //----------------------------------------------------------------------
    var app = new Appointment(service)
    {
        Subject = "Meet George",
        Body = "You need to meet George",
        Location = "1st Floor Boardroom",
        Start = DateTime.Now.AddHours(2),
        End = DateTime.Now.AddHours(3),
        IsReminderSet = true,
        ReminderMinutesBeforeStart = 15
    };
    app.RequiredAttendees.Add(new Attendee("any@gmail.com"));
    app.Save(SendInvitationsMode.SendToAllAndSaveCopy);
}

Some potential answers.

  1. Passing in the wrong url or domain.
  2. Passing in a bad email address.
  3. Rebuilding the Windows Profile can sometimes help. (Warning: have an IT Admin do this). And it might be overkill.
  4. A user could have an old, bad, or multiple outlook profiles set up. The email server name could be bad in the outlook profile. (See Control Panel > Mail)

Autodiscover depends on two things:

  1. DNS entries that point from the users mail domain to the Autodiscover data on the Exchange server. Typically you would have a DNS entry with the name autodiscover.domain.com, but there's more than one way of setting this up for different versions of Exchange. If the correct DNS entry doesn't exist, auto-discovery will fail.

  2. Autodiscover data hosted on the Exchange server (I believe it's an XML file) and accessed over HTTP. If this isn't accessible (perhaps it's behind a firewall) then auto-discovery will fail.

Check the appropriate DNS entries and autodiscover information is accessible to your client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM