locked
GetAttachment: There is an error in XML document - Invalid Character RRS feed

  • Question

  • Hi,

    I have written some code to retrieve envelope journal mail items. Retrieval works about 99.9% of the time. However on occasion when I try to retrieve the original mail item which is attached to the journal report I get the following error:

    There is an error in XML document (54, -111).

    Inner Exception stack looks like this:

    hexadecimal value 0x13, is an invalid character. Line 54, position -111.

    What can be causing this? Is there a way around this, the nature of this application means that I need to be able to retrieve all items 100% of the time. I am using pretty standard code to retrieve the attached mail item, with a call to ExchangeServiceBinding.GetAttachment(...). The call to GetAttachment is throwing the exception mentioned above.

    Thanks in advance!

    Code snippet:

    //Get attached mail item from journal report
    EWS.AttachmentResponseShapeType responseShape = new EWS.AttachmentResponseShapeType();
    responseShape.IncludeMimeContent = true;
    responseShape.IncludeMimeContentSpecified = true;


    EWS.AttachmentIdType attachmentID = new MailMACRetrieval.EWS.AttachmentIdType();
    attachmentID.Id = attachmentItem.AttachmentId.Id; //get id of original item attached to journal report

    EWS.GetAttachmentType request = new EWS.GetAttachmentType();
    request.AttachmentIds = new MailMACRetrieval.EWS.AttachmentIdType[] {attachmentID};
    request.AttachmentShape = responseShape;

    EWS.GetAttachmentResponseType response = esb.GetAttachment(request); //fails here!
    Wednesday, March 25, 2009 10:39 AM

Answers

  • Hello bSect,

    This may be caused by a known issue with auto-generated proxies that require certain characters to be substituted. Try this code snippet:

    public partial class ExchangeServiceBinding : SoapHttpClientProtocol  
    {  
        /// <summary> 
        /// Override the default behavior of the SOAP reader to handle characters which aren't valid in strings  
        /// </summary> 
        /// <param name="message"></param> 
        /// <param name="bufferSize"></param> 
        /// <returns></returns>  
        protected override XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize)  
        {  
            XmlReader retval = base.GetReaderForMessage(message, bufferSize);  
            XmlTextReader xrt = retval as XmlTextReader;  
            if (null != xrt)  
            {  
                xrt.Normalization = false;  
            }  
            return retval;  
        }  

    With regards,
    Michael | Microsoft Exchange SDK
    • Marked as answer by bSect Thursday, April 2, 2009 3:25 PM
    Wednesday, March 25, 2009 5:47 PM

All replies

  • Hello bSect,

    This may be caused by a known issue with auto-generated proxies that require certain characters to be substituted. Try this code snippet:

    public partial class ExchangeServiceBinding : SoapHttpClientProtocol  
    {  
        /// <summary> 
        /// Override the default behavior of the SOAP reader to handle characters which aren't valid in strings  
        /// </summary> 
        /// <param name="message"></param> 
        /// <param name="bufferSize"></param> 
        /// <returns></returns>  
        protected override XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize)  
        {  
            XmlReader retval = base.GetReaderForMessage(message, bufferSize);  
            XmlTextReader xrt = retval as XmlTextReader;  
            if (null != xrt)  
            {  
                xrt.Normalization = false;  
            }  
            return retval;  
        }  

    With regards,
    Michael | Microsoft Exchange SDK
    • Marked as answer by bSect Thursday, April 2, 2009 3:25 PM
    Wednesday, March 25, 2009 5:47 PM
  • Thanks!! That was exactly what I needed.
    Thursday, April 2, 2009 3:25 PM
  • Hi,

    I have the same problem, but my project is in VB.NET. Do you have any suggestions on how to fix this within VB.NET ?




    Thank you very much!


    Marcel
    Sunday, February 14, 2010 3:20 PM
  • Hi,

    How was this implemented as I am just using the web service to bind.

    Regards,


    Marr
    Tuesday, December 7, 2010 2:52 PM
  • Hello Matt,

    Are you using the autogenerated proxy or the EWS Managed API? If you are using the autogenerated proxy, you need to add the partial class definition to your project. This is already implemented in the EWS Managed API.

    With regards,


    Michael | Microsoft Exchange SDK
    Tuesday, December 7, 2010 3:45 PM
  • Hi Michael,

    I also encounter similar issue,  and I'm use Java EWS API, any suggestion how I can work around this :

    This is the error I got:

    The request failed. Illegal character entity: expansion character (code 0xb) not
    a valid XML character
    at [row,col {unknown-source}]: [179,364]
    microsoft.exchange.webservices.data.ServiceRequestException: The request failed.
    Illegal character entity: expansion character (code 0xb) not a valid XML charac
    ter
    at [row,col {unknown-source}]: [179,364]
    at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internal
    Execute(Unknown Source)
    at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execu
    te(Unknown Source)
    at microsoft.exchange.webservices.data.ExchangeService.internalBindToIte
    ms(Unknown Source)
    at microsoft.exchange.webservices.data.ExchangeService.bindToItem(Unknow
    n Source)
    at microsoft.exchange.webservices.data.ExchangeService.bindToItem(Unknow
    n Source)
    at microsoft.exchange.webservices.data.EmailMessage.bind(Unknown Source)

    at microsoft.exchange.webservices.data.EmailMessage.bind(Unknown Source)

    at test.EWSTest.getMessagesFromInbox(EWSTest.java:1636)
    at test.EWSTest.main(EWSTest.java:1718)
    Caused by: com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expa
    nsion character (code 0xb) not a valid XML character
    at [row,col {unknown-source}]: [179,364]
    at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.jav
    a:605)
    at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:461)

    at com.ctc.wstx.sr.StreamScanner.reportIllegalChar(StreamScanner.java:23
    75)
    at com.ctc.wstx.sr.StreamScanner.checkAndExpandChar(StreamScanner.java:2
    321)
    at com.ctc.wstx.sr.StreamScanner.resolveSimpleEntity(StreamScanner.java:
    1180)
    at com.ctc.wstx.sr.BasicStreamReader.readTextSecondary(BasicStreamReader
    .java:4675)
    at com.ctc.wstx.sr.BasicStreamReader.readCoalescedText(BasicStreamReader
    .java:4124)
    at com.ctc.wstx.sr.BasicStreamReader.finishToken(BasicStreamReader.java:
    3699)
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1023)
    at com.ctc.wstx.evt.WstxEventReader.peek(WstxEventReader.java:306)
    at microsoft.exchange.webservices.data.EwsXmlReader.isEmptyElement(Unkno
    wn Source)
    at microsoft.exchange.webservices.data.ComplexPropertyDefinitionBase.loa
    dPropertyValueFromXml(Unknown Source)
    at microsoft.exchange.webservices.data.PropertyBag.loadFromXml(Unknown S
    ource)
    at microsoft.exchange.webservices.data.ServiceObject.loadFromXml(Unknown
    Source)
    at microsoft.exchange.webservices.data.EwsServiceXmlReader.readServiceOb
    jectsCollectionFromXml(Unknown Source)
    at microsoft.exchange.webservices.data.GetItemResponse.readElementsFromX
    ml(Unknown Source)
    at microsoft.exchange.webservices.data.ServiceResponse.loadFromXml(Unkno
    wn Source)
    at microsoft.exchange.webservices.data.MultiResponseServiceRequest.parse
    Response(Unknown Source)
    at microsoft.exchange.webservices.data.ServiceRequestBase.readResponse(U
    nknown Source)
    at microsoft.exchange.webservices.data.SimpleServiceRequestBase.readResp
    onse(Unknown Source)
    ... 9 more

    Thanks.


    James

    Tuesday, May 15, 2012 7:32 PM