Skip to content

Commit f3482ef

Browse files
UPDATED: acessing webservice via localhost vs via domain name issue again. Found out that for some user base, web service via localhost is blocked. Implemented new method to check both localhost and domain name and see which one is accessible.
1 parent 2e9b586 commit f3482ef

1 file changed

Lines changed: 79 additions & 71 deletions

File tree

rqlconnector/rqlactionwebservice.aspx

Lines changed: 79 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,89 @@
11
<%@ Page Language="C#" validateRequest="false" %>
22
<script runat="server">
3-
public class RqlWebServiceConnector
4-
{
5-
public string SendRql(string Rql)
6-
{
7-
HttpContext.Current.Response.ContentType = "text/plain; charset=utf-8";
8-
return SendRqlToWebService(Rql);
9-
}
10-
11-
private string SendRqlToWebService(string Rql)
12-
{
13-
if (string.IsNullOrEmpty(Rql))
14-
return "";
15-
16-
string WebServiceUri = this.GetWebServiceUrl();
17-
18-
string Response = this.SendRqlToWebService(WebServiceUri, Rql);
19-
20-
return Response;
21-
}
22-
23-
private string SendRqlToWebService(string WebServiceUrl, string Rql)
24-
{
25-
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(
26-
delegate
27-
{
28-
return true;
29-
}
30-
);
31-
32-
string Response = "";
33-
System.Net.WebClient oWC = new System.Net.WebClient();
34-
oWC.Headers.Add("Content-Type", "text/xml; charset=utf-8");
35-
oWC.Headers.Add("SOAPAction", "http://tempuri.org/RDCMSXMLServer/action/XmlServer.Execute");
36-
37-
try
3+
public class RqlWebServiceConnector
4+
{
5+
public string SendRql(string Rql)
386
{
39-
Response = oWC.UploadString(WebServiceUrl, Rql);
7+
HttpContext.Current.Response.ContentType = "text/plain; charset=utf-8";
8+
return SendRqlToWebService(Rql);
409
}
41-
catch
10+
11+
private string SendRqlToWebService(string Rql)
4212
{
43-
Response = "";
13+
if (string.IsNullOrEmpty(Rql))
14+
return "";
15+
16+
string WebServiceUri = this.GetWebServiceUrl();
17+
18+
string Response = this.SendRqlToWebService(WebServiceUri, Rql);
19+
20+
return Response;
21+
}
22+
23+
private string SendRqlToWebService(string WebServiceUrl, string Rql)
24+
{
25+
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(
26+
delegate
27+
{
28+
return true;
29+
}
30+
);
31+
32+
string Response = "";
33+
System.Net.WebClient oWC = new System.Net.WebClient();
34+
oWC.Headers.Add("Content-Type", "text/xml; charset=utf-8");
35+
oWC.Headers.Add("SOAPAction", "http://tempuri.org/RDCMSXMLServer/action/XmlServer.Execute");
36+
37+
try
38+
{
39+
Response = oWC.UploadString(WebServiceUrl, Rql);
40+
}
41+
catch
42+
{
43+
Response = "";
44+
}
45+
46+
return Response;
4447
}
4548
46-
return Response;
47-
}
48-
49-
public string GetWebServiceUrl()
50-
{
51-
if (HttpContext.Current.Session["WebServiceUrl"] == null)
52-
{
53-
HttpContext.Current.Session["WebServiceUrl"] = HttpContext.Current.Request.Url.Scheme + ":" + "//" + "localhost" + "/cms/WebService/RqlWebService.svc";
54-
Uri WebServiceUri = new Uri(HttpContext.Current.Session["WebServiceUrl"].ToString());
55-
56-
string Rql = "";
57-
Rql += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
58-
Rql += "<s:Body><q1:Execute xmlns:q1=\"http://tempuri.org/RDCMSXMLServer/message/\"><sParamA></sParamA><sErrorA></sErrorA><sResultInfoA></sResultInfoA></q1:Execute></s:Body>";
59-
Rql += "</s:Envelope>";
60-
61-
string Response = this.SendRqlToWebService(WebServiceUri.ToString(), Rql);
62-
63-
if(Response == "")
64-
{
65-
if (WebServiceUri.Scheme == "https")
66-
{
67-
HttpContext.Current.Session["WebServiceUrl"] = "http" + "://" + WebServiceUri.Authority + WebServiceUri.PathAndQuery;
68-
}
69-
else
70-
{
71-
HttpContext.Current.Session["WebServiceUrl"] = "https" + "://" + WebServiceUri.Authority + WebServiceUri.PathAndQuery;
72-
}
73-
}
74-
}
75-
76-
return HttpContext.Current.Session["WebServiceUrl"].ToString();
77-
}
78-
}
49+
public string GetWebServiceUrl()
50+
{
51+
if (HttpContext.Current.Session["WebServiceUrl"] == null)
52+
{
53+
System.Collections.ArrayList WebServiceUrls = new System.Collections.ArrayList();
54+
string WebServicePath = "/cms/WebService/RqlWebService.svc";
55+
string CurrentUrlScheme = HttpContext.Current.Request.Url.Scheme;
56+
string Domain = HttpContext.Current.Request.Url.Authority;
57+
string LocalHost = "localhost";
58+
string OtherUrlScheme = (CurrentUrlScheme == "https") ? "http" : "https";
59+
60+
WebServiceUrls.Add(String.Format("{0}://{1}{2}", CurrentUrlScheme, Domain, WebServicePath));
61+
WebServiceUrls.Add(String.Format("{0}://{1}{2}", OtherUrlScheme, Domain, WebServicePath));
62+
WebServiceUrls.Add(String.Format("{0}://{1}{2}", CurrentUrlScheme, LocalHost, WebServicePath));
63+
WebServiceUrls.Add(String.Format("{0}://{1}{2}", OtherUrlScheme, LocalHost, WebServicePath));
64+
65+
foreach(string WebServiceUrl in WebServiceUrls)
66+
{
67+
HttpContext.Current.Session["WebServiceUrl"] = WebServiceUrl;
68+
Uri WebServiceUri = new Uri(WebServiceUrl);
69+
70+
string Rql = "";
71+
Rql += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
72+
Rql += "<s:Body><q1:Execute xmlns:q1=\"http://tempuri.org/RDCMSXMLServer/message/\"><sParamA></sParamA><sErrorA></sErrorA><sResultInfoA></sResultInfoA></q1:Execute></s:Body>";
73+
Rql += "</s:Envelope>";
74+
75+
string Response = this.SendRqlToWebService(WebServiceUri.ToString(), Rql);
76+
77+
if(String.IsNullOrEmpty(Response) == false)
78+
{
79+
break;
80+
}
81+
}
82+
}
83+
84+
return HttpContext.Current.Session["WebServiceUrl"].ToString();
85+
}
86+
}
7987
</script>
8088
<%
8189
RqlWebServiceConnector oRqlWebServiceConnector = new RqlWebServiceConnector();

0 commit comments

Comments
 (0)