1
votes

I'hv implemented one CRM 2011 plugin which sends sms to Main Phone of Account record on create. But I'm getting an error saying "Unable to connect to the remote server." Below is the piece of code used in plugin.

    public static void send(string uid, string password, string message, string no)
    {
        HttpWebRequest myReq =
        (HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password +
        "&msg=" + message + "&phone=" + no + "&provider=way2sms");

        HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse(); //Getting error in this line
        System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
        string responseString = respStreamReader.ReadToEnd();
        respStreamReader.Close();
        myResp.Close();
    }

Whats the solution to resolve this error?

1
Not sure if it explains your issue, but you should look into whether you need to URL-encode/escape the various parameters you're injecting into the URL. Also, have you confirmed whether you can retrieve the URL in question manually?reuben
I run the same code in Console application, its sending sms without any error (even when manually pasted the URL).Charan Raju C R
Can you get more error information from the failed request? Also, can you post the full error / exception information?reuben
Inner exception: "No Connection could be made because the target machine actively refuse it 118.139.172.1:80"Charan Raju C R

1 Answers

3
votes

If you are running this Plug-in as Sandboxed, there are some limitations by default on the Outbound URI pattern:

These default Web access restrictions are defined in a registry key on the server running the Microsoft.Crm.Sandbox.HostService.exe process. The value of the registry key can be changed by the System Administrator according to business and security needs. The registry key path on the server is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM\SandboxWorkerOutboundUriPattern

The key value is a regular expression string that defines the Web access restrictions. The default key value is:

"^http[s]?://(?!((localhost[:/])|([.*])|([0-9]+[:/])|(0x[0-9a-f]+[:/])|(((([0-9]+)|(0x[0-9A-F]+)).){3}(([0-9]+)|(0x[0-9A-F]+))[:/]))).+";

By changing this registry key value, you can alter the allowed Web access for sandboxed plug-ins.