繁体   English   中英

服务器无法执行EWS自动发现

[英]Server unable to execute EWS autodiscover

在我们的测试服务器上,EWS自动发现不起作用。 为了从原因列表中消除错误的IIS选项,我用C&P组合了WindowsForms应用程序(下面的代码),并将其与Microsoft.Exchange.Webservice.dll一起放入我具有写权限的文件夹中。

不幸的是,没有创建xml和文本文件。 相反,我收到Unhandled Exception错误。

System.NullReferenceException 
   at System.Windows.Forms.TextBoxBase.AppendText(String text)

在同一个AD域中并且测试应用程序始终返回自动发现成功的开发机器上,不会发生这种情况。

问题:为什么没有跟踪输出生成?

所以现在,我的应用代码:

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;

namespace ADDebugWin
{
    public partial class Form1 : Form
    {
        public static string traceData;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
            ews.TraceListener = new TraceListener();
            // Optional flags to indicate the requests and responses to trace.
            ews.TraceFlags = TraceFlags.EwsRequest | TraceFlags.EwsResponse;
            ews.TraceEnabled = true;
            ews.UseDefaultCredentials = true;
            try {
                ews.AutodiscoverUrl("email@mydomain.com");
                textBox1.AppendText("AutoDiscover erfolgreich.");
            } catch (Exception ex) {
                textBox1.AppendText(traceData);
                textBox1.AppendText(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
    }
}

TraceListener.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ADDebugMvc.Controllers;
using Microsoft.Exchange.WebServices.Data;
using System.Xml;

namespace ADDebugMvc.Models
{

    class TraceListener : ITraceListener
    {
        public void Trace(string traceType, string traceMessage)
        {
            CreateXMLTextFile(traceType, traceMessage.ToString());
            HomeController.traceData += traceType + " " + traceMessage.ToString() + "\r\n";
        }

        private void CreateXMLTextFile(string fileName, string traceContent)
        {
            // Create a new XML file for the trace information.
            try
            {
                // If the trace data is valid XML, create an XmlDocument object and save.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(traceContent);
                xmlDoc.Save(fileName + ".xml");
            }
            catch
            {
                // If the trace data is not valid XML, save it as a text document.
                System.IO.File.WriteAllText(fileName + ".txt", traceContent);
            }
        }
    }
}

应该注意的是

 ews.TraceFlags = TraceFlags.EwsRequest | TraceFlags.EwsResponse;

在自动发现过程中不返回任何跟踪。

ews.TraceFlags = TraceFlags.All;确实。)

因此,没有将字符串附加到traceData,这就是为什么将traceData==null >将其附加到TextBox时发生异常。

暂无
暂无

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

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