Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;“请求失败”;在部分受信任的AppDomain中调用WCF操作时_C#_.net_Wcf_Appdomain_Code Access Security - Fatal编程技术网

C# &引用;“请求失败”;在部分受信任的AppDomain中调用WCF操作时

C# &引用;“请求失败”;在部分受信任的AppDomain中调用WCF操作时,c#,.net,wcf,appdomain,code-access-security,C#,.net,Wcf,Appdomain,Code Access Security,我有一个完全信任的.NET4.5应用程序,它创建了一个部分信任的AppDomain。我正在尝试通过名为管道的WCF与此域通信 我已成功创建服务并连接到它。然而,当我尝试调用服务的任何方法时,我得到了一个不太有用的错误: “System.Security.SecurityException”类型的未处理异常 发生在System.ServiceModel.Internals.dll中 其他信息:请求失败 就这些,没有例外 正如调用堆栈所建议的,异常是从受限AppDomain引发的。毫不奇怪,如果我以

我有一个完全信任的.NET4.5应用程序,它创建了一个部分信任的AppDomain。我正在尝试通过名为管道的WCF与此域通信

我已成功创建服务并连接到它。然而,当我尝试调用服务的任何方法时,我得到了一个不太有用的错误:

“System.Security.SecurityException”类型的未处理异常 发生在System.ServiceModel.Internals.dll中

其他信息:请求失败

就这些,没有例外

正如调用堆栈所建议的,异常是从受限AppDomain引发的。毫不奇怪,如果我以完全信任的方式创建域,问题就会消失

包含服务的程序集在受限AppDomain中完全受信任(请参阅下面的代码)。它可以创建管道,为什么我尝试使用它时它会阻塞?这是一个诱使它在接收服务请求时声明其权限的问题吗

完全信任代码:
我的答案是抛弃WCF,使用老式的
MarshallByRefObject
来实现我的接口。现在一切都很好

尽管MSDN文档中有关于远程处理过时的可怕警告,但对于进程内通信来说,它仍然是一个非常好的选择(有时是唯一的选择…)。它也不会很快消失

>   System.ServiceModel.Internals.dll!System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(uint error, uint bytesRead, System.Threading.NativeOverlapped* nativeOverlapped) + 0x75 bytes 
    mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x6e bytes    
    [Native to Managed Transition]  
    [Appdomain Transition]  
    [Native to Managed Transition]  
    kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes    
    ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes   
    ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes    
var evidence = new Evidence(null, new EvidenceBase[] { new Zone(SecurityZone.Internet) });

var setup = new AppDomainSetup() { ApplicationBase = InstallDirectory.FullName };
setup.PrivateBinPath = String.Join(Path.PathSeparator.ToString(), "Episodes", "bin");

var permissions = new PermissionSet(null);
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));

GameDomain = AppDomain.CreateDomain("Bulletin.Game", evidence, setup, permissions, 
    typeof(Shared.IBulletinGame).Assembly.Evidence.GetHostEvidence<StrongName>(),
    typeof(Bulletin.Game).Assembly.Evidence.GetHostEvidence<StrongName>()
    );

Activator.CreateInstanceFrom(GameDomain, Path.Combine(InstallDirectory.FullName, "bin", "Bulletin.dll"), "Bulletin.Game");

GameService = new ChannelFactory<Shared.IBulletinGame>(
    new NetNamedPipeBinding(),
    new EndpointAddress("net.pipe://localhost/Bulletin/Game")
    ).CreateChannel();

GameService.Test(); // throws exception
[assembly: AllowPartiallyTrustedCallers()]

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Game : Shared.IBulletinGame
{
    // The constructor completes successfully.
    [SecurityCritical]
    public Game()
    {
        Host = new ServiceHost(this);
        Host.AddServiceEndpoint(typeof(Shared.IBulletinGame), new NetNamedPipeBinding(), "net.pipe://localhost/Bulletin/Game");
        Host.Open();
    }

    // Control doesn't even reach this method when I try to remotely call it,
    // unless I give the AppDomain full trust.
    public void Test()
    {
        System.Diagnostics.Debugger.Break();
    }
}