Reputation: 35822
Context
I am calling WCF service from a CRM plugin using the generated client. (System.ServiceModel.ClientBase<T>
) The CRM plugin must work in sandbox isolation mode. The WCF client was generated from pure wsdl and xsd's. It seems it is using Xml serialization, so no reflection is involved.
The plugin execution throws:
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission,
In the stack trace it seems it is coming from the core of WCF client implementation:
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)
Question
Is the statement correct we can not use WCF client in sandbox isolation mode and in CRM Online? (or am I missing something...?)
If so what is the workaround? Do we have to reimplement all message rendering and parsing?
Upvotes: 4
Views: 541
Reputation: 21
the standard 'services references' (or the old web references for that matter) that you can generate in visual studio wont work in sandbox mode. it uses the Microsoft serializer (from System.Runtime.Serialization) which isn't supported in a sandbox for any class not registered in the GAC by default.
As far as i know there is no quick fix for this. the link provides 2 possible alternative solutions, but neither will work with service references directly.
Upvotes: 1
Reputation: 505
Is your WCF service hosted with HTTPS? This is mandatory for Sandboxed plugins in CRM Online. IP addresses cannot be used either. You must use a named web address that requires DNS name resolution
Upvotes: 0