accessing wcf-web service from PlugIns or Custom Workflows under Sandbox Isolation Mode at Dynamics CRM
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;
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...
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...
Comments
Post a Comment