以编程方式自动发现服务 [英] Autodiscover Service programmatically

查看:60
本文介绍了以编程方式自动发现服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是软件开发人员。我正在尝试使用C#以编程方式创建自动发现客户端。

I am software developer. I am trying to make an autodiscover client programmatically in C#.

我使用了以下代码:

 

string xml ="<?xml version = \" 1.0 \" encoding = \" utf-8 \"?>< xs:schema"

string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xs:schema"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +" xmlns = \" http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\""

            + "xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\""

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +" xmlns:mstns = \" http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\" xmlns:xs = \" http://www.w3.org/2001/XMLSchema\""

            + "xmlns:mstns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +" targetNamespace = \" http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\""

            + "targetNamespace=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\""

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +" elementFormDefault = \" unqualified\" id = \" requestschema2006 \">"

            + "elementFormDefault=\"unqualified\" id=\"requestschema2006\">"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:element name = \" Autodiscover \">"

            + "<xs:element name=\"Autodiscover\">"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:complexType>"

            + "<xs:complexType>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:sequence>"

            + "<xs:sequence>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:element name = \" Request \" type = \" RequestType \" />"

            + "<xs:element name=\"Request\" type=\"RequestType\"/>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< / xs:sequence>"

            + "</xs:sequence>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< / xs:complexType>"

            + "</xs:complexType>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< / xs:element>"

            + "</xs:element>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:complexType name = \" RequestType \">"

            + "<xs:complexType name=\"RequestType\">"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:sequence>"

            + "<xs:sequence>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:sequence>"

            + "<xs:sequence>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:element name = \" xxxxxx @ microsoft.com \" type = \" xs:string \" />"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< xs:element name = \" AcceptableResponseSchema \" type = \" xs:string \" />"

            + "<xs:element name=\"AcceptableResponseSchema\" type=\"xs:string\"/>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< / xs:sequence>"

            + "</xs:sequence>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< / xs:sequence>"

            + "</xs:sequence>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< / xs:complexType>"

            + "</xs:complexType>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; +"< / xs:schema>" ;;

            + "</xs:schema>";

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string url =" https://autodiscover.microsoft.com/autodiscover/autodiscover.xml" ;;

            string url = "https://autodiscover.microsoft.com/autodiscover/autodiscover.xml";

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HttpWebRequest req =(HttpWebRequest)WebRequest.Create(url);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; req.Credentials = new NetworkCredential(" xxxxxx@microsoft.com"," xxxxxxx");

            req.Credentials = new NetworkCredential("xxxxxx@microsoft.com", "xxxxxxx");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; byte [] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);

            byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; req.Method =" POST";

            req.Method = "POST";

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; req.ContentType =" text / xml";

            req.ContentType = "text/xml";

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; req.ContentLength = requestBytes.Length;

            req.ContentLength = requestBytes.Length;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;流requestStream = req.GetRequestStream();

            Stream requestStream = req.GetRequestStream();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; requestStream.Write(requestBytes,0,requestBytes.Length);

            requestStream.Write(requestBytes, 0, requestBytes.Length);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; requestStream.Close();

            requestStream.Close();

 

 

 

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;试试

            try

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

            {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HttpWebResponse res =(HttpWebResponse)req.GetResponse();

                HttpWebResponse res = (HttpWebResponse)req.GetResponse();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StreamReader sr = new StreamReader(res.GetResponseStream(),System.Text.Encoding.Default);

                StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string backstr = sr.ReadToEnd();

                string backstr = sr.ReadToEnd();

 

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; sr.Close();

                sr.Close();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; res.Close();

                res.Close();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }

            }

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; catch(Exception ex)

            catch (Exception ex)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {}

            { }

 

但是返回的响应是无效请求错误代码600.所以该怎么办?

but the response returned is invalid request error code 600. so what should i do ??

 

推荐答案

您好,

EWS托管API(< a href ="http://www.microsoft.com/download/en/details.aspx?id=13480"target ="_ blank"> http://www.microsoft.com/download/en/details.aspx? id = 13480 )已经实现了自动发现过程。

the EWS Managed API (http://www.microsoft.com/download/en/details.aspx?id=13480) already implements the AutoDiscover process.

如果你想自己做,你可能会了解它是如何做到的。您可以在ExchangeService实例上启用跟踪,该实例会将AutoDiscover请求转储到控制台。这可能有助于解决您的问题。

If you want to do it on your own, you might learn something on how it does it. You can enable tracing on the ExchangeService instance which will dump the AutoDiscover requests to the console. This might help to troubleshoot your problem.

亲切的问候,

Henning

Kind regards,
Henning


这篇关于以编程方式自动发现服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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