开发者

How to read Exchange 2010 SP 1 public folder using c#

I am trying to read a public folder hosted in ExchangeServer 2010 SP1. Well I am able to connect but when I am trying to read the folder I am getting stragne error. Hope somebody will able to share his/her experience. Below is the code what I am executing doing and after that the error SoapException was Unhandled I am getting.

ExchangeServiceBinding serviceBinding = new ExchangeServiceBinding();
    serviceBinding.Credentials = new NetworkCredential("XXXXXXXX", "YYYYYY", "zzzzzzzz");
    serviceBinding.RequestServerVersionValue = new RequestServerVersion();
    serviceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP1;
    serviceBinding.Url = @"https://the.domain.of.my.work/EWS/exchange.asmx";

    DistinguishedFolderIdType publicFolderRoot = new DistinguishedFolderIdType();
    publicFolderRoot.Id = DistinguishedFolderIdNameType.publicfoldersroot;
    FindFolder(serviceBinding, publicFolderRoot, @"All Public Folders");

private static FolderIdType FindFolder(ExchangeServiceBinding esb, BaseFolderIdType folderId, string folderName)
        {

            //FindPublicFolderType request = new FindPublicFolderType();
            FindFolderType request = new FindFolderType();
            request.Traversal = FolderQueryTraversalType.Shallow;
            request.FolderShape = new FolderResponseShapeType();
            request.FolderShape.BaseShape = DefaultShapeNamesType.AllProperties;
            request.ParentFolderIds = new BaseFolderIdType[] { folderId };

            //Giving error at this below 
             FindFolderResponseType response = esb.FindFolder(request);

            foreach (ResponseMessageType rmt in response.ResponseMessages.Items)
            {
                if (rmt.ResponseClass == ResponseClassType.Success)
                {
                    FindFolderResponseMessageType ffResponse = (FindFolderResponseMessageType)rmt;

                    if (ffResponse.RootFolder.TotalItemsInView > 0)
                    {
                        foreach (BaseFolderType subFolder in ffResponse.RootFolder.Folders)
                            if (subFolder.DisplayName == folderName)
                                return subFolder.FolderId;
                        return null;
                    }
                    Console.WriteLine("Can't find '" + folderName + "'.");
                }

                else
                {

                    //Console.WriteLine("Response was: " + rmt.ResponseClass + Environment.NewLine + rmt.MessageText);
                    MessageBox.Show("Response was: " + rmt.ResponseClass + Environment.NewLine + rmt.MessageText);

                }

            }

            return null;

        }

After executing the above code I am facing error mentioned below

System.Web.Services.Protocols.SoapException
System.Web.Services.Protocols.SoapException
was unhandled   Message="The mailbox
that was requested doesn't support the
specified RequestServerVersion."  
Source="System.Web.Services"  
Actor=""   Lang="en-US"   Node=""  
Role=""   StackTrace:
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream
responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
       at RnDExchangePublicFolder.ExchangeWebServices.ExchangeServiceBinding.FindFolder(FindFolderType
FindFolder1) in
E:\Data\VS2008\RnDExchangePublicFolder\RnDExchangePublicFolder\Web
References\ExchangeWebServices\Re开发者_如何学Pythonference.cs:line
547
       at RnDExchangePublicFolder.Form1.FindFolder(ExchangeServiceBinding
esb, BaseFolderIdType folderId, String
folderName) in
E:\Data\VS2008\RnDExchangePublicFolder\RnDExchangePublicFolder\Form1.cs:line
51
       at RnDExchangePublicFolder.Form1.btnConnect_Click(Object
sender, EventArgs e) in
E:\Data\VS2008\RnDExchangePublicFolder\RnDExchangePublicFolder\Form1.cs:line
39
       at System.Windows.Forms.Control.OnClick(EventArgs
e)
       at System.Windows.Forms.Button.OnClick(EventArgs
e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message&
m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message&
m)
       at System.Windows.Forms.ButtonBase.WndProc(Message&
m)
       at System.Windows.Forms.Button.WndProc(Message&
m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&
m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr
lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32
pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form
mainForm)
       at RnDExchangePublicFolder.Program.Main()
in
E:\Data\VS2008\RnDExchangePublicFolder\RnDExchangePublicFolder\Program.cs:line
18
       at System.AppDomain._nExecuteAssembly(Assembly
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)
       at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Can somebody share their experience what is causing the issue or to further proceed.?

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜