在我们的测试服务器上,EWS自动发现不起作用。为了从原因列表中消除错误的IIS选项,我将一个WindowsForms应用程序(下面的代码)与C {和}一起放在一起,并与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);
}
}
}
}
答案 0 :(得分:0)
应该注意
ews.TraceFlags = TraceFlags.EwsRequest | TraceFlags.EwsResponse;
在自动发现期间未返回任何跟踪。
(ews.TraceFlags = TraceFlags.All;
确实。)
因此没有字符串附加到traceData,这就是为什么traceData==null
- >将其附加到TextBox时出现异常。