入门Exchange Web服务2010 [英] Getting started with Exchange Web Services 2010

查看:300
本文介绍了入门Exchange Web服务2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在负责.NET编写一个SOAP Web服务是EWS2010和以前使用的WebDAV连接到Exchange的应用程序之间的中间件。 (据我了解,WebDAV是要走了用EWS2010,因此应用程序服务器将不再能够像以前一样连接,它是指数难以连接到EWS没有WebDAV的,该理论认为这样做在.net应该比什么都更容易,对吧?!的)



我的最终目标是要能够获取创建/更新电子邮件,日历,联系人和待办事项列表中指定的Exchange帐户的项目。 (删除当前不是必要的,但我可以建立它在未来的考虑,如果它是很容易做到)。



我原本是给一些示例代码,这实际上做的工作,但我很快意识到这是过时的。所使用的类型和类无处出现在当前文档



例如,用于创建到Exchange服务器的连接方法是:

  ExchangeService SVC =新ExchangeService(); 
svc.Credentials =新WebCredentials(AuthEmailAddress,AuthEmailPassword);
svc.AutodiscoverUrl(AutoDiscoverEmailAddress);

有关它的价值,这是使用的示例代码来组装: Microsoft.Exchange.WebServices.dll (监测和预警系统)。



在我意识到,这是不是当前的标准方法完成连接,它的工作,我试图建立它,并添加了一个方法来创建日历项目,这是我的从这里复制的:

 静态无效CreateAppointment(ExchangeServiceBinding ESB)
{
/ /创建约会。
CalendarItemType任命=新CalendarItemType();


}



马上,我米面临的 ExchangeService ExchangeServiceBinding (ESB)的区别;于是我开始谷歌搜索,试图找出如何让ESB的定义,以便 CreateAppointment 方法编译。我发现这个博客帖子了解释了如何从一个WSDL,我做了一个代理类。



不幸的是,这引起了一些冲突,如在原有大会中定义的类型, Microsoft.Exchange.WebServices.dll (与示例代码来),在我的新的 EWS.dll 组件类型重叠(我从生成的代码编译 services.w​​sdl 由Exchange服务器提供)。



我排除的监测和预警系统总成,只把事情弄得更糟。我从错误和警告极少数赴25个错误和2,510警告。各种类型和方法都没有发现。事情显然是错误的,在这里。



于是我就回到了追捕。我发现添加服务引用和Web引用(即它需要在额外的步骤说明VS2008 ),我觉得我回到了正确的轨道上。



我删除(实际上,现在,只要除外)以前的所有组件我有一直在努力;我添加了 https://my.exchange-server.com/ews/services.w​​sdl



服务引用< 。p>现在我到只有1错误和警告1




警告:

元素运输不能包含子元素extendedProtectionPolicy,因为父元素的内容模型是空的。




这是在提到这是做的web.config当我添加了服务引用的变化;我刚刚发现修复为这里SO 。我评论说出来部分所示,和它做了警告消失,所以活泉了点。



错误已经不那么容易解决,虽然:




错误:

类型或命名空间名称'ExchangeService找不到(是否缺少using指令或程序集引用?)




这是在参考了功能我用创建EWS连接,每一个的Web方法调用:

 私人ExchangeService的getService(字符串AutoDiscoverEmailAddress,字符串AuthEmailAddress,字符串AuthEmailPassword )
{
ExchangeService SVC =新ExchangeService();
svc.Credentials =新WebCredentials(AuthEmailAddress,AuthEmailPassword);
svc.AutodiscoverUrl(AutoDiscoverEmailAddress);
返回SVC;
}

这功能完全从示例代码的监测和预警系统组装工作,但 ExchangeService 类型不再可用。 (也不是 ExchangeServiceBinding ,这是我检查的第一件事。)



在这一点上,因为我不从文档以下任何指示(我不是说是一个服务引用添加到您的Exchange服务器的services.w​​sdl的文档中找到任何地方 - 但是这似乎是最好的/最远我到目前为止得到) ,我觉得我盲目。



我知道我需要弄清楚什么,那就是应该替换 ExchangeService / ExchangeServiceBinding ,实施,然后通过任何工作失误冒出来作为交换的结果...



但我不知道该怎么做,或者到哪里寻找如何做到这一点。谷歌搜索ExchangeService和ExchangeServiceBinding似乎只是导致回过时的博客文章和MSDN,既不其中已被证明非常有用迄今。



我应该替换 ExchangeService / ExchangeServiceBinding 用?有一些其他的位置,与EWS比MSDN好?


解决方案

我会建议迁移到托管EWS API的工作文件。它更容易比试图凑齐自己的一切使用。它同时支持Exchange 2007 SP1和Exchange 2010的我想你会发现它更容易使用,可能会消除你的问题。



版本1:
下面是微软中的下载。



和这里的 MSDN文档



有关第2版(感谢@ruffin!)



Download - 的MSDN文档






添加人问题提问者:



这证明其他环节有所帮助:




I've been tasked with writing a SOAP web-service in .Net to be middleware between EWS2010 and an application server that previously used WebDAV to connect to Exchange. (As I understand it, WebDAV is going away with EWS2010, so the application server will no longer be able to connect as it previously did, and it is exponentially harder to connect to EWS without WebDAV. The theory is that doing it in .Net should be easier than anything else... Right?!)

My end goal is to be able to get and create/update email, calendar items, contacts, and to-do list items for a specified Exchange account. (Deleting is not currently necessary, but I may build it in for future consideration, if it's easy enough).

I was originally given some sample code, which did in fact work, but I quickly realized that it was outdated. The types and classes used appear nowhere in the current documentation.

For example, the method used to create a connection to the Exchange server was:

ExchangeService svc = new ExchangeService();
svc.Credentials = new WebCredentials(AuthEmailAddress, AuthEmailPassword);
svc.AutodiscoverUrl(AutoDiscoverEmailAddress);

For what it's worth, this was using an assembly that came with the sample code: Microsoft.Exchange.WebServices.dll ("MEWS").

Before I realized that this wasn't the current standard way to accomplish the connection, and it worked, I tried to build on it and add a method to create calendar items, which I copied from here:

static void CreateAppointment(ExchangeServiceBinding esb)
{
    // Create the appointment.
    CalendarItemType appointment = new CalendarItemType();

    ...
}

Right away, I'm confronted with the difference between ExchangeService and ExchangeServiceBinding ("ESB"); so I started Googling to try and figure out how to get an ESB definition so that the CreateAppointment method will compile. I found this blog post that explains how to generate a proxy class from a WSDL, which I did.

Unfortunately, this caused some conflicts where types that were defined in the original Assembly, Microsoft.Exchange.WebServices.dll (that came with the sample code) overlapped with Types in my new EWS.dll assembly (which I compiled from the code generated from the services.wsdl provided by the Exchange server).

I excluded the MEWS assembly, which only made things worse. I went from a handful of errors and warnings to 25 errors and 2,510 warnings. All kinds of types and methods were not found. Something is clearly wrong, here.

So I went back on the hunt. I found instructions on adding service references and web references (i.e. the extra steps it takes in VS2008), and I think I'm back on the right track.

I removed (actually, for now, just excluded) all previous assemblies I had been trying; and I added a service reference for https://my.exchange-server.com/ews/services.wsdl

Now I'm down to just 1 error and 1 warning.

Warning:
The element 'transport' cannot contain child element 'extendedProtectionPolicy' because the parent element's content model is empty.

This is in reference to a change that was made to web.config when I added the service reference; and I just found a fix for that here on SO. I've commented that section out as indicated, and it did make the warning go away, so woot for that.

The error hasn't been so easy to get around, though:

Error:
The type or namespace name 'ExchangeService' could not be found (are you missing a using directive or an assembly reference?)

This is in reference to the function I was using to create the EWS connection, called by each of the web methods:

private ExchangeService getService(String AutoDiscoverEmailAddress, String AuthEmailAddress, String AuthEmailPassword)
{
    ExchangeService svc = new ExchangeService();
    svc.Credentials = new WebCredentials(AuthEmailAddress, AuthEmailPassword);
    svc.AutodiscoverUrl(AutoDiscoverEmailAddress);
    return svc;
}

This function worked perfectly with the MEWS assembly from the sample code, but the ExchangeService type is no longer available. (Nor is ExchangeServiceBinding, that was the first thing I checked.)

At this point, since I'm not following any directions from the documentation (I couldn't find anywhere in the documentation that said to add a service reference to your Exchange server's services.wsdl -- but that does seem to be the best/farthest I've gotten so far), I feel like I'm flying blind.

I know I need to figure out whatever it is that should replace ExchangeService / ExchangeServiceBinding, implement that, and then work through whatever errors crop up as a result of that switch...

But I have no idea how to do that, or where to look for how to do it. Googling "ExchangeService" and "ExchangeServiceBinding" only seem to lead back to outdated blog posts and MSDN, neither of which has proven terribly helpful thus far.

What should I replace ExchangeService / ExchangeServiceBinding with? Is there some other location that documents working with EWS that is better than MSDN?

解决方案

I would recommend moving to the Managed EWS API. It's much easier to use than trying to cobble everything together yourself. It supports both Exchange 2007 SP1 and Exchange 2010. I think you'll find it much easier to use and will probably eliminate your issues.

Version 1: Here is the download from Microsoft.

And here are the MSDN docs.

For Version 2 (thanks @ruffin!)

Download - MSDN Docs


Added by question asker:

Additional links that proved helpful:

这篇关于入门Exchange Web服务2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆