none
Invalid XML error when using EWS API RRS feed

  • Question

  • Hi,

    I'm currently trying to create an appointment on Exchange Server 2010 using VB.NET code. However, I get an error when I run this code: The response received from the service didn't contain valid XML. I know the problematic line of code is: "appointment.Save(SendInvitationsMode.SendToNone)". But I'm not sure whether the Exchange Server or my code is at fault (or both).

     

    Attached code and error output for reference.

    Imports System.Net
    Imports System.Security.Cryptography.X509Certificates
    
    Public Class Form1
    
     Public Sub New()
      ' This call is required by the designer.
      InitializeComponent()
    
      'try to connect to MS Exchange
      System.Net.ServicePointManager.CertificatePolicy = New MyPolicy
      Dim service As New ExchangeService()
      service.Credentials = New WebCredentials("<username>", "<password>")
      service.Url = New Uri("https://<exchange-server-internal-ip>/EWS/Exchange.asmx")
    
      Dim appointment As New Appointment(service)
      appointment.Subject = "Dentist Appointment"
      appointment.Body = "The appointment is with Dr. Smith."
      appointment.Start = New DateTime(2011, 7, 26, 9, 0, 0)
      appointment.[End] = appointment.Start.AddHours(2)
      appointment.Save(SendInvitationsMode.SendToNone)
     End Sub
    End Class
    
    
     Public Class MyPolicy
      Implements Net.ICertificatePolicy
      Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
       Return True
      End Function
     End Class
    

     

     

     

    System.InvalidOperationException was unhandled
     Message=An error occurred creating the form. See Exception.InnerException for details. The error is: The response received from the service didn't contain valid XML.
     Source=HelloExchange
     StackTrace:
      at HelloExchange.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
      at HelloExchange.My.MyProject.MyForms.get_Form1()
      at HelloExchange.My.MyApplication.OnCreateMainForm() in <omitted>
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
      at HelloExchange.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
      at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
      at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
     InnerException: Microsoft.Exchange.WebServices.Data.ServiceRequestException
      Message=The response received from the service didn't contain valid XML.
      Source=Microsoft.Exchange.WebServices
      StackTrace:
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadXmlDeclaration(EwsServiceXmlReader reader)
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadSoapFault(EwsServiceXmlReader reader)
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException)
       at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(HttpWebRequest& request)
       at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
       at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
       at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling)
       at Microsoft.Exchange.WebServices.Data.ExchangeService.CreateItem(Item item, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode)
       at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode)
       at Microsoft.Exchange.WebServices.Data.Item.Save()
       at HelloExchange.Form1..ctor() in <omitted>
      InnerException: System.Xml.XmlException
       Message=Root element is missing.
       Source=System.Xml
       LineNumber=0
       LinePosition=0
       SourceUri=""
       StackTrace:
         at System.Xml.XmlTextReaderImpl.Throw(Exception e)
         at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
         at System.Xml.XmlTextReaderImpl.Read()
         at System.Xml.XmlTextReader.Read()
         at System.Xml.XmlCharCheckingReader.Read()
         at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read()
         at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read(XmlNodeType nodeType)
         at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadXmlDeclaration(EwsServiceXmlReader reader)
       InnerException: 
    
    

     

     


    Tuesday, July 26, 2011 10:26 PM

Answers

  • Hi,

    I have fixed the problem. For posterity, I upgraded to to Exchange Server 2010 SP1 and that fixed the problem.

    • Marked as answer by Hac Phan Wednesday, July 27, 2011 9:59 PM
    Wednesday, July 27, 2011 9:58 PM

All replies

  • Hi,

    have you enabled tracing on the ews instance? Please drill down into the exception. The InnerException does contain more information in this case (probably multiple level of innerexceptions here..).

    Next step would be to look at the data at a lower level: Use Fiddler (http://www.fiddler2.com/fiddler2/) to look at the data that is exchanged. Fiddler can decrypt SSL encrypted data, but you need to enable that feature in the options of the program.

    Henning

    Wednesday, July 27, 2011 4:15 AM
  • Going to the deepest level of InnerException says the problem is in System.xml with the message "Root element is missing."

     

     InnerException: System.Xml.XmlException
      Message=Root element is missing.
      Source=System.Xml
    


    Wednesday, July 27, 2011 5:02 PM
  • Hi,

    The the EWS tracing feature might help you to determine what's going on here.

    Set the TraceEnabled property to true on your ExchangeService instance. The requests and responses are then dumped to the console.

    Kind regards,
    Henning

    "Hac Phan" wrote in message news:2431760d-260d-4918-95b4-9b1a0d00c063@communitybridge.codeplex.com...

    Going to the deepest level of InnerException says the problem is in System.xml with the message "Root element is missing."

    InnerException: System.Xml.XmlException
     Message=Root element is missing.
     Source=System.Xml
    
    Wednesday, July 27, 2011 5:09 PM
  • Hi,

    I have fixed the problem. For posterity, I upgraded to to Exchange Server 2010 SP1 and that fixed the problem.

    • Marked as answer by Hac Phan Wednesday, July 27, 2011 9:59 PM
    Wednesday, July 27, 2011 9:58 PM