c# – 从CRM沙盒插件调用WCF(使用生成的客户端)抛出System.Security.SecurityException

上下文

我正在使用生成的客户端从CRM插件调用WCF服务. (System.ServiceModel.ClientBase< T>)CRM插件必须在沙箱隔离模式下工作. WCF客户端是从纯wsdl和xsd生成的.它似乎正在使用Xml序列化,因此不涉及任何反射.

插件执行抛出:

System.Security.SecurityException: Request for the permission of type ‘System.Security.Permissions.SecurityPermission,

在堆栈跟踪中,它似乎来自WCF客户端实现的核心:

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Crm.Sandbox.ISandboxHost.ExecuteCustomWorkflowActivityAndReturnTraceInfo(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, String assemblyContents, Boolean returnTraceInfo)
at Microsoft.Crm.Sandbox.SandboxCustomActivity.Execute(SandboxClient client, SandboxCallTracker callTracker, IExecutionContext requestContext, String assemblyContents, Boolean returnTraceInfo)
at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)

声明是否正确我们不能在沙箱隔离模式和CRM Online中使用WCF客户端? (或者我错过了什么……?)

如果是这样,解决方法是什么?我们是否必须重新实现所有消息呈现和解析?

最佳答案 您可以在visual studio中生成的标准“服务引用”(或旧的Web引用)不会在沙盒模式下工作.它使用Microsoft序列化程序(来自System.Runtime.Serialization),默认情况下,沙箱中不支持任何未在GAC中注册的类.

http://www.instantquick.com/index.php/serialization-in-sandbox-solutions?c=elumenotion-blog-archive/random-whatnot

据我所知,没有快速解决方案.该链接提供了2种可能的替代解决方案,但两种解决方案都不能直接与服

点赞