I'm trying to implement Microsoft's social networking solution accelerator on my Dynamics CRM deployment. I've resolved a number of issues with the code already but this last one has me stumped. The Social Networking Accelerator (hereafter referred to as SNA) uses the following code to get data from Twitter:
case "GET":
WebClient wCli = new WebClient();
if (_creds != null)
{
wCli.Credentials = _creds;
}
try
{
using (Stream str = wCli.OpenRead(_URL))
{
using (StreamReader reader = new StreamReader(str))
{
responseXml = reader.ReadToEnd();
}
}
}
catch (WebException ex)
{
if (ex.Response is HttpWebResponse)
{
if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
{
return null;
}
}
throw ex;
}
Obviously there is a lot of setup prior to calling this code.
When I run this code within visual studio, or within a test harness outside of Dynamics CRM, it works as expected and returns a string containing XML returned from Twitter.
But, when I run it inside my CRM system (as part of the workflow) I receive a 'Protocol Error' at the point where the code executes wCli.OpenRead(_URL). I've traced the execution and in both cases the same URL and Twitter credentials are used, outside the CRM system everything works, inside CRM, I get the error:
{"The remote server returned an error: (403) Forbidden."}
I suspect this might be caused by the fact that I'm running behind an ISA web proxy server, however the logging console in ISA suggests that the web request is never getting that far. Something is causing this to stall at source. Anyone got any suggestions?
I've confirmed that this is in fact a proxy problem. I'm not sure I fully understand why it is a problem, but I tried this little fix and it did work:
case "GET":
WebClient wCli = new WebClient();
if (_creds != null)
{
wCli.Credentials = _creds;
}
//[TPL] Configure web proxy
IWebProxy proxy = new WebProxy("sbs", 8080);
proxy.Credentials = new NetworkCredential(@"DOMAIN\User", "password");
wCli.Proxy = proxy;
try
{
Obviously this needs to be made configurable somehow, but it has proved the concept.