从控制台应用程序调用Dynamics CRM Web服务时如何指定代理详细信息

时间:2019-06-12 04:44:56

标签: c# proxy dynamics-crm webclient crm

我是Dynamics CRM Web服务的新手,我想从控制台应用程序使用Web服务,它在本地运行,但是在生产服务器上则无法使用,因为生产服务器需要在调用之前设置代理网络服务。有人可以在调用Web服务之前解释如何使用代理,这是在我的本地计算机上运行的代码

android:gravity="center_vertical|center_horizontal"

1 个答案:

答案 0 :(得分:0)

下面是HttpWebResponse的示例代码

ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
                    WebProxy proxy = new WebProxy("proxy.xyz.local", 81) { UseDefaultCredentials = true };
                    WebRequest request = WebRequest.Create(globaConfigStatciValues.Url);
                    request.Proxy = proxy;
                    request.Method = "GET";
                    request.Credentials = new NetworkCredential(globaConfigStatciValues.userName,
                        globaConfigStatciValues.Password);


                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        try
                        {
                            if (response.StatusCode == HttpStatusCode.OK)
                            {
                                isConnectionSucessfull = true;
                                tracing.Trace($" Resposne is correct  {response.StatusCode}");
                                TracingMessage += $"Resposne is correct  {response.StatusCode} \n";
                            }
                            else
                            {
                                TracingMessage += $"Response from connecting to API {response.StatusCode} \n";
                                tracing.Trace($"Response from connecting to API {response.StatusCode}");
                            }

                        }
                        catch (Exception e)
                        {
                            TracingMessage += $" In catch block {e} \n";
                            tracing.Trace($" In catch block {e}");
                            createLogRecord( e.StackTrace,TracingMessage);
                           // throw new Exception($"There was an issue with connecting to API {e.Message}");
                        }
                    }