EWS 1.1 XML Problem

Hi,

I'm using EWS 1.1 in a C# webapp to retrieve mailbox folders, the code is pretty simple:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.TraceEnabled = true;
service.TraceListener = new EWSTrace();
service.Url = new Uri(strUriEWS);
service.Credentials = new WebCredentials(username, password, domain);
FindFoldersResults ffResults = service.FindFolders(WellKnownFolderName.Root, fvFolderView);

But it always fails with Exchange 2010 with this exception: "The response received from the service didn't contain valid XML.". The inner exception is: "Data at the root level is invalid. Line 1, position 1."

I have enabled the trace and the result seems fine to me (I can post it if needed, but it is very long), the EWSResponseHTTPHeaders.txt is:

200 OK
X-EwsPerformanceData: RpcC=3;RpcL=0;LdapC=0;LdapL=0;
Persistent-Auth: true
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: Keep-Alive
Content-Length: 6455
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Date: Tue, 13 Dec 2011 14:58:37 GMT
Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET

With Exchange 2007 I did not have this problem. Any suggestion ?

Andrea

 

December 13th, 2011 6:02pm

What is the value of strUriEWS?  Check the IIS logs to make sure the request is going where you think it is.  Can you show us the full response you got for the .FindFolders?
Free Windows Admin Tool Kit Click here and download it now
December 13th, 2011 6:55pm

Hi Lee, thank you for you answer.

The strUriEWS points to https://exchange2010.fqdn/EWS/Exchange.asmx and it is corrects, I have checked it.

I cannot post the whole EWSResposnse.txt file, it is tool long, bu it starts with:

8000
<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="355" MinorBuildNumber="2" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <m:FindFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <m:ResponseMessages>
                <m:FindFolderResponseMessage ResponseClass="Success">
                    <m:ResponseCode>NoError</m:ResponseCode>
                    <m:RootFolder IndexedPagingOffset="77" TotalItemsInView="77" IncludesLastItemInRange="true">
                        <t:Folders>
                            <t:SearchFolder>
                                <t:FolderId Id="AAMkADAyNTdhMGJiLTE4MDgtNDRmNS05YWMwLThlZDI0ZDM0MDg0NQAuAAAAAABHAVP75W4pRaMBZRo932R9AQAh/OJ71aRASZ3pBm2P0MydAAAAAUa2AAA=" ChangeKey="BwAAABYAAAAh/OJ71aRASZ3pBm2P0MydAAAAAUa6"/>
                                <t:ParentFolderId Id="AAMkADAyNTdhMGJiLTE4MDgtNDRmNS05YWMwLThlZDI0ZDM0MDg0NQAuAAAAAABHAVP75W4pRaMBZRo932R9AQAUTxRW/hUCR6DhKEzS09edAAAAAmxyAAA=" ChangeKey="AQAAAA=="/>
                                <t:FolderClass>IPF</t:FolderClass>
                                <t:DisplayName>AllItems</t:DisplayName>
                                <t:TotalCount>12090</t:TotalCount>
                                <t:ChildFolderCount>0</t:ChildFolderCount>
                                <t:ExtendedProperty>
                                    <t:ExtendedFieldURI PropertyTag="0xe08" PropertyType="Long"/>
                                    <t:Value>0</t:Value>
                                </t:ExtendedProperty>
                                <t:EffectiveRights>
                                    <t:CreateAssociated>true</t:CreateAssociated>
                                    <t:CreateContents>true</t:CreateContents>
                                    <t:CreateHierarchy>true</t:CreateHierarchy>
                                    <t:Delete>true</t:Delete>
                                    <t:Modify>true</t:Modify>
                                    <t:Read>true</t:Read>
                                </t:EffectiveRights>
                                <t:UnreadCount>237</t:UnreadCount>
                            </t:SearchFolder>
                            <t:Folder>
                                <t:FolderId Id="AAMkADAyNTdhMGJiLTE4MDgtNDRmNS05YWMwLThlZDI0ZDM0MDg0NQAuAAAAAABHAVP75W4pRaMBZRo932R9AQAdPzBnXsTdQ52D9k/QFFnCACu8YKdtAAA=" ChangeKey="AQAAABYAAAAh/OJ71aRASZ3pBm2P0MydAAAAAVG1"/>
                                <t:ParentFolderId Id="AAMkADAyNTdhMGJiLTE4MDgtNDRmNS05YWMwLThlZDI0ZDM0MDg0NQAuAAAAAABHAVP75W4pRaMBZRo932R9AQAUTxRW/hUCR6DhKEzS09edAAAAAmxyAAA=" ChangeKey="AQAAAA=="/>
                                <t:DisplayName>BlackBerryHandheldInfo</t:DisplayName>
                                <t:TotalCount>2</t:TotalCount>
                                <t:ChildFolderCount>4</t:ChildFolderCount>
                                <t:ExtendedProperty>
                                    <t:ExtendedFieldURI PropertyTag="0xe08" PropertyType="Long"/>
                                    <t:Value>268</t:Value>
                                </t:ExtendedProperty>
                                <t:EffectiveRights>
                                    <t:CreateAssociated>true</t:CreateAssociated>
                                    <t:CreateContents>true</t:CreateContents>
                                    <t:CreateHierarchy>true</t:CreateHierarchy>
                                    <t:Delete>true</t:Delete>
                                    <t:Modify>true</t:Modify>
                                    <t:Read>true</t:Read>
                                </t:EffectiveRights>
                                <t:UnreadCount>0</t:UnreadCount>
                            </t:Folder>

then there is a long list of folders, and:

                            <t:Folder>
                                <t:FolderId Id="AAMkADAyNTdhMGJiLTE4MDgtNDRmNS05YWMwLThlZDI0ZDM0MDg0NQAuAAAAAABHAVP75W4pRaMBZRo932R9AQAUTxRW/hUCR6DhKEzS09edAAAAAmx7AAA=" ChangeKey="AQAAABYAAAAUTxRW/hUCR6DhKEzS09edAAAAAm6J"/>
                                <t:ParentFolderId Id="AAMkADAyNTdhMGJiLTE4MDgtNDRmNS05YWMwLThlZDI0ZDM0MDg0NQAuAAAAAABHAVP75W4pRaMBZRo932R9AQAUTxRW/hUCR6DhKEzS09edAAAAAmxyAAA=" ChangeKey="AQAAAA=="/>
                                <t:DisplayName>Views</t:DisplayName>
                                <t:TotalCount>0</t:TotalCount>
                                <t:ChildFolderCount>0</t:ChildFolderCount>
                                <t:ExtendedProperty>
                                    <t:ExtendedFieldURI PropertyTag="0xe08" PropertyType="Long"/>
                                    <t:Value>68749</t:Value>
                                </t:ExtendedProperty>
                                <t:EffectiveRights>
                                    <t:CreateAssociated>true</t:CreateAssociated>
                                    <t:CreateContents>true</t:CreateContents>
                                    <t:CreateHierarchy>true</t:CreateHierarchy>
                                    <t:Delete>true</t:Delete>
                                    <t:Modify>true</t:Modify>
                                    <t:Read>true</t:Read>
                                </t:EffectiveRights>
                                <t:UnreadCount>0</t:UnreadCount>
                            </t:Folder>
                        </t:Folders>
                    </m:RootFolder>
                </m:FindFolderResponseMessage>
            </m:ResponseMessages>
        </m:FindFolderResponse>
        16
    </s:Body>
</s:Envelope>
0


The initial 8000 and the final 0 are part of the EWSResponse.txt file produced by EWS 1.1

Thank you

Andrea

December 13th, 2011 7:27pm

Are you using Visual Studio?  How do you get it to produce an EWSResponse.txt file?  I'll see if I can duplicate it here.  I would be surprised if the 8000 and 0 were actually supposed to be there.  That 16 near the end seems a bit isolated, too.

Free Windows Admin Tool Kit Click here and download it now
December 13th, 2011 7:45pm

Yes, I'm using VS 2010. To produce EWSResponse.txt I have enabled Trace in the service:
service.TraceEnabled = true; 
service.TraceListener = new EWSTrace(); 


EWSTrace is a class that implements ITraceListener
public class EWSTrace : ITraceListener
        {
            #region ITraceListener Members

            public void Trace(string traceType, string traceMessage)
            {
                CreateXMLTextFile(traceType, traceMessage.ToString());
            }

            #endregion

            private void CreateXMLTextFile(string fileName, string traceContent)
            {
                string basePath = @"C:\Users\Andrea\";

                // Create a new XML file for the trace information.
                try
                {
                    // If the trace data is valid XML, create an XmlDocument object and save.
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(traceContent);
                    xmlDoc.Save(basePath + fileName + ".xml");
                }
                catch
                {
                    // If the trace data is not valid XML, save it as a text document.
                    System.IO.File.WriteAllText(basePath + fileName + ".txt", traceContent);
                }
            }
        }

 

I agree with you that the isolated numbers seem to be the cause of the problem.


Thank you

Andrea

December 13th, 2011 8:11pm

Okay, I got that working.  As expected, I don't see those numbers in mine.  Where yours come from, I've no idea.  Interestingly enough, I do get .txt files saved, which (according to that EWSTrace code) means that I'm not getting valid XML either.  But it looks okay to me.  Those spurious numbers definitely aren't there, though.

Since this is coming from compiled server-side code, we don't really have the option of looking at it.  It might be worth removing and recreating the EWS VDir using powershell.

Free Windows Admin Tool Kit Click here and download it now
December 13th, 2011 9:23pm

Thank you Lee,

I have made more tests with EWS, and even trying a different operation, send an email, I have isolated numbers in the response

3b5
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
	<s:Header>
		<h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="355" MinorBuildNumber="2" Version="Exchange2010_SP1"
			xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
                        xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
	</s:Header>
	<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"><m:CreateItemResponse
                xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
                xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
	<m:ResponseMessages>
		<m:CreateItemResponseMessage ResponseClass="Success">
			<m:ResponseCode>NoError</m:ResponseCode>
			<m:Items/>
		</m:CreateItemResponseMessage>
	</m:ResponseMessages>
	</m:CreateItemResponse>
16
	</s:Body>
</s:Envelope>
0


it seems to me that they are the size of the following chunck of the message (after the 16 there are exactly 22 chars before the end of the response). So maybe the problem could be due to the client library and not the server. I'm currently using EWS Managed 1.1

What do you think ?

Andrea

 

 

December 14th, 2011 3:55pm

Right now, anything seems possible.  I've written a little thing here that will allow you to test EWS another way:

http://www.leederbyshire.com/Articles/EWS-FindItem-List-Inbox-Exchange-2007.asp

You could easily make a small change to get it to display what is being returned.

Free Windows Admin Tool Kit Click here and download it now
December 14th, 2011 4:07pm

Hi Lee,

I have tested your code, but it prints only 200-OK, so it seems that it is not able to process the response XML, probably because it is not well formatted directly from the server.

Thank you again

Andrea

December 14th, 2011 6:29pm

Hmm.  This is just too strange.  How do you feel about removing and recreating your EWS VDir using powershell?
Free Windows Admin Tool Kit Click here and download it now
December 14th, 2011 6:39pm

I'd be very happy to do that, but unfortunately the Exchange server is not under my control.

It is, in some way, outsourced :-(

Is there a way to print the raw XML received ? I could send it to the Exchange Admins to show them my problem.

Andrea

December 14th, 2011 6:44pm

From my code example, you mean?  If you can make a few small changes:

 

1.  Add a textarea near the end, just before </body>

  <p><textarea id="txt1" rows="25" cols="75"></textarea>

2.  Add a line of code just before the line Set objXMLHTTP = Nothing

  txt1.innerText = objXMLHTTP.ResponseText

 

That ought to do it.

Free Windows Admin Tool Kit Click here and download it now
December 14th, 2011 7:02pm

Thank you so much. It worked. And the responseTXT field contains the numbers.

Andrea

December 14th, 2011 7:24pm

Something strange is definitely happening at the server end, then.  It's a shame you don't have access to it, because I don't see how you can fix it now.  It's as if some pointless ISAPI filter has been installed on the server that is slightly changing the output.  Or the exchange server-side code has been modified somehow.
Free Windows Admin Tool Kit Click here and download it now
December 14th, 2011 7:36pm

Thank you Lee,

I have opened a call with the Exchange Administrators, and passed them the link to this discussion :-)

Andrea

December 15th, 2011 11:41am

I have the same issue.  After your Exchange Admins removed and recreated the vdir, did that fix the issue?

thanks,
-m

Free Windows Admin Tool Kit Click here and download it now
December 20th, 2011 3:42am

Any solution to this issue?

We are seeing similiar in our environment - Exchange 2010 SP2 RU4v2 with an F5 BigIP 1600 in front for load balancing. We only seem to incur the issue when routing through the load balancer.

Thanks,

Brandon

November 21st, 2012 1:10am

Yip same issue here. We are getting same problem when we are using EWS from the Load balanced Exchange 2010. Slight difference is the problem is intermittent, and only happens when there is high volume of traffic on F5.

Only work around is bypass the F5.



Free Windows Admin Tool Kit Click here and download it now
July 16th, 2013 2:56pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics