4
votes

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?

2
Yes, that was my first google result before I asked the question. Unfortunatelly WebClient is far low level component than WCF SOAP client (which is working with generated types and renders SOAP req/reponses.) Using WebClient we must practicaly reimplement SOAP, and many accompaining standardsg.pickardou

2 Answers

1
votes

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.

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

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.

0
votes

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