使用 Windows 身份验证从 Mono 调用 WCF 服务

From Mono call WCF service with Windows Authentication

我在带有 IIS 的 Windows 服务器上托管了一个 WCF 服务,并设置为 Windows 身份验证(公司内部的用户必须使用域身份验证才能登录他们的桌面)。我想使用 Mono 从 linux (ubuntu) 调用此 WCF 服务。我们使用 netTcp 协议,但它可以改变。我将服务创建为:

var s = new WebTestService.TestServiceClient();
s.ClientCredentials.UserName.UserName = "mydomain\myuser";
s.ClientCredentials.UserName.Password = "myPassword";

但是还是不能通讯。

有谁知道在哪里可以修复此错误?可以解决吗?先谢谢了。

Unhandled Exception: System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) [0x00052] in :0 at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x000b4] in :0
--- End of inner exception stack trace --- at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_remoting_wrapper (intptr,intptr)
at (wrapper remoting-invoke) MonoTest.WebTestService.ITestService:GetIdentity () at MonoTest.WebTestService.TestServiceClient.GetIdentity () [0x00007] in <27f805f676fd42ad978ebb382e24c2d7>:0 at MonoTest.Program.Main (System.String[] args) [0x00050] in <27f805f676fd42ad978ebb382e24c2d7>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) [0x00052] in :0 at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x000b4] in :0 --- End of inner exception stack trace --- at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_remoting_wrapper (intptr,intptr)
at (wrapper remoting-invoke) MonoTest.WebTestService.ITestService:GetIdentity () at MonoTest.WebTestService.TestServiceClient.GetIdentity () [0x00007] in <27f805f676fd42ad978ebb382e24c2d7>:0 at MonoTest.Program.Main (System.String[] args) [0x00050] in <27f805f676fd42ad978ebb382e24c2d7>:0

我在我的一个 wcf 网络服务中使用用户名和密码进行 windows 身份验证,我像这样分配用户名和密码:

s.ClientCredentials.Windows.ClientCredential.UserName = "mydomain\myuser";
//in my case I don't use a domain though.
s.ClientCredentials.Windows.ClientCredential.Password = "myPassword";
//I acutally use .SecurePassword and assign it SecureString

我能够让它在 Mono 上运行。

即使使用 "anonymous" 身份验证,netTcpBinding 也无法正常工作(根据我的经验)。

wsHttpBinding 将不起作用(未实现方法或操作)。

只有 basicHttpBinding 有效。它适用于 TransportCredentialOnlyTransport 安全模式,具有 clientCredentialType Windows 传输设置。在这种情况下,客户端可以设置 "domain\username" 格式的用户名和密码。