示例#1
0
        public void ParseResponse(string commandName, WebRequestResponse response)
        {
            if (response.Response.StatusCode == HttpStatusCode.Unauthorized)
            {
                throw new CommandAuthorizationException(string.Format("Authorization failed: {0}", response.Response.ReasonPhrase));
            }

            string xml = response.ResponseBody;

            XDocument xdoc = null;

            string xmlValidationErrorMessage;

            if (!EwsXmlHelper.IsValidXml(xml, out xmlValidationErrorMessage))
            {
                if (this.RequireValidXml)
                {
                    throw new CommandResponseXmlException(string.Format("Invalid xml content: {0}", xmlValidationErrorMessage));
                }
            }
            else
            {
                xdoc = XDocument.Load(new StringReader(xml));
            }

            this.ParseResponseCore(commandName, xdoc, response);
        }
示例#2
0
        public void ParseResponse(string commandName, WebRequestResponse response)
        {
            if (response.Response.StatusCode == HttpStatusCode.Unauthorized)
            {
                throw new CommandAuthorizationException(string.Format("Authorization failed: {0}", response.Response.ReasonPhrase));
            }

            string xml = response.ResponseBody;

            string xmlValidationErrorMessage;

            if (!EwsXmlHelper.IsValidXml(xml, out xmlValidationErrorMessage))
            {
                throw new CommandResponseXmlException(string.Format("Invalid xml content: {0}", xmlValidationErrorMessage));
            }

            var root = XDocument.Load(new StringReader(xml)).Root;

            if (response.Response.IsSuccessStatusCode)
            {
                // read error section
                var error = root.XGetChild("Response/Error", NsEwsAutodiscover);
                if (error != null)
                {
                    string errorCode = error.XGetChildValue <string>("ErrorCode", NsEwsAutodiscover);
                    string message   = error.XGetChildValue <string>("Message", NsEwsAutodiscover);
                    string debugData = error.XGetChildValue <string>("DebugData", NsEwsAutodiscover);

                    LogService.Log("AutoDiscoverResult", string.Format("Error response code: {0} message: {1} debug data: {2}", errorCode, message, debugData));
                    return;
                }

                // read protocols section
                var nodes = root.XGetChildrenOf("Response/Account", NsEwsOutlookAutodiscover);
                foreach (var node in nodes)
                {
                    if (node.Name != null && node.Name.LocalName.Equals("Protocol", StringComparison.OrdinalIgnoreCase))
                    {
                        var type   = node.XGetChildValue <string>("Type", NsEwsOutlookAutodiscover);
                        var ewsUrl = node.XGetChildValue <string>("EwsUrl", NsEwsOutlookAutodiscover);

                        // read more about protocol type: http://blogs.technet.com/b/exchange/archive/2008/09/26/3406344.aspx
                        if (type.Equals("exch", StringComparison.OrdinalIgnoreCase))
                        {
                            this.InternalEwsUrl = ewsUrl;
                        }
                        else if (type.Equals("expr", StringComparison.OrdinalIgnoreCase))
                        {
                            this.ExternalEwsUrl = ewsUrl;
                        }
                    }
                    else if (node.Name != null && node.Name.LocalName.Equals("RedirectAddr", StringComparison.OrdinalIgnoreCase))
                    {
                        this.RedirectEmailAddress = node.Value;
                    }
                }
            }
        }