简体   繁体   English

如何声明Exchange Web服务

[英]How to declare Exchange Web Service

I have in my c# application a new web service that I generated using Add Web Reference tool. 我在c#应用程序中有一个新的Web服务,我使用Add Web Reference工具生成。

It is called ExchangeWebServices in my Solution Explorer. 它在我的解决方案资源管理器中称为ExchangeWebServices

But when I try to add the sample code that I found on StackOverflow: 652549: read-ms-exchange-email-in-c-sharp it won't compile. 但是当我尝试添加我在StackOverflow上找到的示例代码时:652549:read-ms-exchange-email-in-c-sharp它将无法编译。

I have a compile error message that 我有一个编译错误消息

ExchangeWebServices is a namespace but is used as a type.

here is the line of code that I am trying to use. 这是我尝试使用的代码行。

ExchangeWebServices service =new ExchangeWebServices(ExchangeVersion.Exchange2013_SP3);

I have at the top of my form class this: 我在表格的顶部有这个:

using email2case_winForm.ExchangeWebServices;

what am I doing wrong here please? 我在这做错了什么?

I am going to guess that the code in the answer to the other stack isn't quite correct, but is more of a concept for how things could be written ( Edit - Or its written against an older version of EWS). 我猜测其他堆栈的答案中的代码不太正确,但更多的是关于如何编写内容的概念( 编辑 - 或者它是针对旧版本的EWS编写的)。 Either way, there are some excellent examples here: http://msdn.microsoft.com/en-us/library/office/bb408521(v=exchg.140).aspx . 无论哪种方式,这里有一些很好的例子: http//msdn.microsoft.com/en-us/library/office/bb408521(v = exchg.140).aspx

Taking the guts of it, you should probably end up with something like: 考虑到它的内涵,你应该最终得到类似的东西:

// Identify the service binding and the user.
ExchangeServiceBinding service = new ExchangeServiceBinding();
service.RequestServerVersionValue = new RequestServerVersion();
service.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
service.Credentials = new NetworkCredential("<username>", "<password>", "<domain>");
service.Url = @"https://<FQDN>/EWS/Exchange.asmx";

From there you can use the service to create requests or whatever it is you need to do. 从那里,您可以使用该服务创建请求或您需要做的任何事情。 Note this code was copied from the msdn link above so you'll want to refer back to that for further explanation. 请注意,此代码是从上面的msdn链接复制的,因此您需要参考该代码以获得进一步说明。 Best of luck! 祝你好运!

Instead of using the Add Web Reference tool to generate the Web service client, I highly suggest that you use the EWS Managed API instead. 我强烈建议您使用EWS托管API,而不是使用“添加Web引用”工具来生成Web服务客户端。 It is a much easier object model to use and it has some useful business logic built into it. 它是一个更容易使用的对象模型,它内置了一些有用的业务逻辑。 It will save you time and lines of code. 它将节省您的时间和代码行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM