【发布时间】:2018-07-20 08:26:50
【问题描述】:
以下代码在 Windows 上运行良好,但在 debian 上返回 401 - 不允许匿名请求。它使用的是 DotNet 核心 2.0.0。如果这有帮助。我认为这可能是因为 Windows 上的机器以某种方式发现了域,而 debian 机器却没有。我不知道。任何帮助表示赞赏。
using System;
using Microsoft.Exchange.WebServices.Data;
namespace Test
{
class Program
{
static void Main(string[] args)
{
ExchangeService service = new ExchangeService();
service.EnableScpLookup = false;
service.TraceEnabled = true;
service.UseDefaultCredentials = false;
service.PreAuthenticate = false;
service.TraceFlags = TraceFlags.All;
try
{
service.Url = new Uri("https:/domain/ews/Exchange.asmx");
}
catch (Exception ex) {
throw new Exception(string.Format("webService Uri:" + ex));
}
try
{
service.Credentials = new WebCredentials("username", "pass","domain");
}
catch (Exception ex) {
throw new Exception(string.Format("Credentials:" + ex));
}
try
{
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("user@domain.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
email.Save();
email.Send();
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
}
}
}
编辑 1:如果有帮助,我可以把肥皂的痕迹和电子邮件的异常省略:
<trace Tag="EwsRequestHttpHeaders" Tid="1" Time="2018-07-20 09:31:08Z">
POST /ews/Exchange.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
Accept: text/xml
User-Agent: ExchangeServicesClient/15.00.0913.015
Accept-Encoding: gzip,deflate
</Trace>
<Trace Tag="EwsRequest" Tid="1" Time="2018-07-20 09:31:09Z"
Version="15.00.0913.015">
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013_SP1" />
</soap:Header>
<soap:Body>
<m:CreateItem MessageDisposition="SaveOnly">
<m:Items>
<t:Message>
<t:Subject>HelloWorld</t:Subject>
<t:Body BodyType="HTML">This is the first email I've sent by using the EWS Managed API</t:Body>
<t:ToRecipients>
<t:Mailbox>
<t:EmailAddress>**********@******.com</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</m:Items>
</m:CreateItem>
</soap:Body>
</soap:Envelope>
</Trace>
<Trace Tag="EwsResponseHttpHeaders" Tid="1" Time="2018-07-20 09:31:12Z">
HTTP/1.1 401 Anonymous Request Disallowed
Server: Microsoft-IIS/8.5
request-id: 13c632cd-7642-4e26-ad5d-48dce4b52d35
WWW-Authenticate: Negotiate, NTLM
X-Powered-By: ASP.NET
X-FEServer: FTLPEX02CAS02
Date: Fri, 20 Jul 2018 09:31:11 GMT
Content-Length: 0
</Trace>
【问题讨论】:
-
不是真的,我尝试缓存我的凭据,然后将 NTML 指定为身份验证类型,然后发送它,这在 Windows 上工作正常(就像我的原始代码一样),但在 Debian 上也有同样的错误.不过可能我理解错了。
-
我也尝试将 DotNet 核心版本更改为 2.1,但这给了我一些奇怪的 kerberos 错误
标签: c# .net linux asp.net-core exchangewebservices