web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Dynamics of Things / accessing wcf-web service f...

accessing wcf-web service from PlugIns or Custom Workflows under Sandbox Isolation Mode at Dynamics CRM

Muhammet ATALAY Profile Picture Muhammet ATALAY 60
If you want to make an external web service call inside PlugIn or Workflow in dynamics CRM (even under sandbox) , Use following code at your PlugIn or Custom Workflows;





edwed wedwed 



                        try
                        {
                            BasicHttpBinding httpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
                            httpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                            httpbinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

                            httpbinding.CloseTimeout = new TimeSpan(0, 5, 0);

                            System.ServiceModel.Channels.Binding binding = httpbinding;

                            System.ServiceModel.EndpointAddress remoteAddress = new EndpointAddress("http://abc.com.tr/xyzService.svc");

                            xyzServiceClient client = new xyzServiceClient(binding, remoteAddress);
                            var methodResult = Convert.ToBase64String(client.GetData(xxxPathinString));
                            ....
                         

                        }
                        catch (System.Security.SecurityException exp)
                        {
                            //Log exception to the Plugin Trace Log:
                            tracingService.Trace("Exception occured in xyzMethod call :" + exp.Message);
                        }
                        catch (ArgumentException exp)
                        {
                            //Log exception to the Plugin Trace Log:
                            tracingService.Trace("Exception occured in xyzMethod call :" + exp.Message);
                        }
                        catch (WebException exception)
                        {
                            string str = string.Empty;
                            if (exception.Response != null)
                            {
                                using (StreamReader reader =
                                    new StreamReader(exception.Response.GetResponseStream()))
                                {
                                    str = reader.ReadToEnd();
                                }
                                exception.Response.Close();
                            }
                            if (exception.Status == WebExceptionStatus.Timeout)
                            {
                                throw new InvalidPluginExecutionException(
                                    "The timeout elapsed while attempting to issue the request.", exception);
                            }
                            throw new InvalidPluginExecutionException(String.Format(CultureInfo.InvariantCulture,
                                "A Web exception occurred while attempting to issue the request. {0}: {1}",
                                exception.Message, str), exception);
                        }
                        catch (Exception exp)
                        {
                            //Log exception to the Plugin Trace Log:
                            tracingService.Trace("Exception occured in xyzMethod call :" + exp.Message);
                        }


enjoy...

This was originally posted here.

Comments

*This post is locked for comments