C# Debian而非windows上的Exchange Web Services 401错误
下面的代码在windows上运行良好,但在debian上返回的401匿名请求是不允许的。它使用的是dotnetcore2.0.0。如果有帮助的话。我认为这可能是因为windows上的机器以某种方式发现了域,而debian机器却没有。我不确定。感谢您的帮助C# Debian而非windows上的Exchange Web Services 401错误,c#,.net,linux,asp.net-core,exchangewebservices,C#,.net,Linux,Asp.net Core,Exchangewebservices,下面的代码在windows上运行良好,但在debian上返回的401匿名请求是不允许的。它使用的是dotnetcore2.0.0。如果有帮助的话。我认为这可能是因为windows上的机器以某种方式发现了域,而debian机器却没有。我不确定。感谢您的帮助 using System; using Microsoft.Exchange.WebServices.Data; namespace Test { class Program { static void Mai
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:如果有帮助,我可以将soap跟踪和异常与电子邮件一起提交:
<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>
POST/ews/Exchange.asmx HTTP/1.1
内容类型:text/xml;字符集=utf-8
接受:text/xml
用户代理:ExchangeServicesClient/15.00.0913.015
接受编码:gzip,deflate
你好世界
这是我使用EWS托管API发送的第一封电子邮件
**********@******网站
HTTP/1.1 401不允许匿名请求
服务器:Microsoft IIS/8.5
请求id:13c632cd-7642-4e26-ad5d-48dce4b52d35
WWW认证:协商,NTLM
X-Powered-By:ASP.NET
X-FEServer:FTLPEX02CAS02
日期:2018年7月20日星期五09:31:11 GMT
内容长度:0
这个答案有帮助吗:?没有,我尝试缓存我的凭据,然后将NTML指定为身份验证类型,然后将其发送,这在Windows上可以正常工作(我的原始代码也是如此),但在Debian上有相同的错误。但我可能误解了。我也尝试将DotNet核心版本更改为2.1,但这给了我一些奇怪的kerberos错误