Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a webservice like:
C#
[WebMethod()]
       [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
       public string userRequest(ClsRequest objClsRequest)
       {
           string sMessage = string.Empty;
           ClsUserRequestProcess objClsUserRequestProcess = new ClsUserRequestProcess();

           sMessage = objClsUserRequestProcess.userRequestProcess(objClsRequest);

           return sMessage;
       }

---------------------------
C#
public class ClsUserRequestProcess
   {
       public string userRequestProcess(ClsRequest objClsRequest)
       {
           ClsResult objClsResult = new ClsResult();
           ClsCommonMethods objClsCommonMethods = new ClsCommonMethods();

           string sMessage = string.Empty;
           string sRequestType = objClsRequest.sRequestType;
           string sRequestFor = objClsRequest.sServiceRequest;

           int iSuccess = 0;
           try
           {
               if (sRequestType.ToUpper() == "APP")
               {
                   #region App requests

                   using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
                   {
                       con.Open();
                       if (objClsCommonMethods.validateUser(objClsRequest.iUserId, objClsRequest.sProvideId))
                       {
                           if (objClsCommonMethods.validateApp(objClsRequest.iAppId, objClsRequest.sBundleId))
                           {
                               if (sRequestFor.ToUpper() == "FIRSTREQUEST")
                               {
                                   #region User record update after app request and before installation
                                   string sUserAppQry = "Select Count(*) as UserAppCount from tblUserActivityTracking" +
                                                      " where UserId=" + objClsRequest.iUserId + " and ProviderId='" + objClsRequest.sProvideId + "'" +
                                                      " and AppId=" + objClsRequest.iAppId + " and BundleId='" + objClsRequest.sBundleId + "'" +
                                                      " and Activity='App'";

                                   using (SqlDataAdapter sqlDa = new SqlDataAdapter(sUserAppQry, con))
                                   {
                                       DataSet dsUserApp = new DataSet();
                                       sqlDa.Fill(dsUserApp);

                                       if (dsUserApp != null && dsUserApp.Tables.Count > 0 && dsUserApp.Tables[0].Rows.Count > 0 && Convert.ToInt32(dsUserApp.Tables[0].Rows[0]["UserAppCount"]) == 0)
                                       {
                                           string sAddUserAppQry = "Insert into tblUserActivityTracking(Activity, UserId, ProviderId, BundleId, " +
                                                                   " AppId, IsRequest, RequestDate, EarnPoint, Status)" +
                                                                   " values('App'," + objClsRequest.iUserId + ",'" + objClsRequest.sProvideId + "'," +
                                                                   " '" + objClsRequest.sBundleId + "'," + objClsRequest.iAppId + "," +
                                                                   " 1, getDate(), 0, 1)";

                                           SqlCommand cmdAddUserApp = new SqlCommand(sAddUserAppQry);
                                           cmdAddUserApp.Connection = con;
                                           iSuccess = cmdAddUserApp.ExecuteNonQuery();

                                           if (iSuccess > 0)
                                           {
                                               objClsResult.bResult = true;
                                               objClsResult.sMessage = "Success";
                                           }
                                           else
                                           {
                                               objClsResult.bResult = false;
                                               objClsResult.sMessage = "Error";
                                           }
                                       }
                                       else
                                       {
                                           string sUpdateUserAppQry = "Update tblUserActivityTracking set IsRequest=1, RequestDate=getDate()" +
                                                                      " where UserId=" + objClsRequest.iUserId + " and ProviderId='" + objClsRequest.sProvideId + "'" +
                                                                      " and AppId=" + objClsRequest.iAppId + " and BundleId='" + objClsRequest.sBundleId + "'" +
                                                                      " and Activity='App'";

                                           SqlCommand cmdUpdateUserApp = new SqlCommand(sUpdateUserAppQry);
                                           cmdUpdateUserApp.Connection = con;
                                           iSuccess = cmdUpdateUserApp.ExecuteNonQuery();

                                           if (iSuccess > 0)
                                           {
                                               objClsResult.bResult = true;
                                               objClsResult.sMessage = "Success";
                                           }
                                           else
                                           {
                                               objClsResult.bResult = false;
                                               objClsResult.sMessage = "Error";
                                           }
                                       }
                                   }
                                   #endregion
                               }
                               else if (sRequestFor.ToUpper() == "INSTALL")
                               {
                                   #region User record update after app installation
                                   string sUserAppQry = "Select Count(*) as UserAppCount from tblUserActivityTracking" +
                                                      " where UserId=" + objClsRequest.iUserId + " and ProviderId='" + objClsRequest.sProvideId + "'" +
                                                      " and AppId=" + objClsRequest.iAppId + " and BundleId='" + objClsRequest.sBundleId + "'" +
                                                      " and Activity='App' and IsRequest=1";

                                   using (SqlDataAdapter sqlDa = new SqlDataAdapter(sUserAppQry, con))
                                   {
                                       DataSet dsUserApp = new DataSet();
                                       sqlDa.Fill(dsUserApp);

                                       if (dsUserApp != null && dsUserApp.Tables.Count > 0 && dsUserApp.Tables[0].Rows.Count > 0 && Convert.ToInt32(dsUserApp.Tables[0].Rows[0]["UserAppCount"]) > 0)
                                       {
                                           string sUpdateUserAppQry = "Update tblUserActivityTracking set IsInstall=1, InstallDate=getDate()" +
                                                                      " where UserId=" + objClsRequest.iUserId + " and ProviderId='" + objClsRequest.sProvideId + "'" +
                                                                      " and AppId=" + objClsRequest.iAppId + " and BundleId='" + objClsRequest.sBundleId + "'" +
                                                                      " and Activity='App' and IsRequest=1";

                                           SqlCommand cmdUpdateUserApp = new SqlCommand(sUpdateUserAppQry);
                                           cmdUpdateUserApp.Connection = con;
                                           iSuccess = cmdUpdateUserApp.ExecuteNonQuery();

                                           if (iSuccess > 0)
                                           {
                                               objClsResult.bResult = true;
                                               objClsResult.sMessage = "Success";
                                           }
                                           else
                                           {
                                               objClsResult.bResult = false;
                                               objClsResult.sMessage = "Error";
                                           }
                                       }
                                       else
                                       {
                                           objClsResult.bResult = false;
                                           objClsResult.sMessage = "Error";
                                       }
                                   }
                                   #endregion
                               }
                           }
                           else
                           {
                               objClsResult.bResult = false;
                               objClsResult.sMessage = "Invalid Request";
                           }
                       }
                       else
                       {
                           objClsResult.bResult = false;
                           objClsResult.sMessage = "Invalid User";
                       }
                   }

                   #endregion
               }
           }
           catch (Exception ex)
           {
               objClsResult.bResult = false;
               objClsResult.sMessage = "Error";
           }
           finally
           {
               sMessage = JsonConvert.SerializeObject(objClsResult);
           }

           return sMessage;
       }
   }


and consumming in MVC 4.0 project by adding service reference and code like:

C#
public class AppRequestsController : Controller
    {
        InstaearnEntities objInstaearnEntities = new InstaearnEntities();
        public ActionResult FirstRequest(int userId, string providerId, string bundleId, int appId)
        {
            //LocalInstaearnWebServiceRef.InstaearnServiceSoapClient objInstaearnServiceSoapClient = new LocalInstaearnWebServiceRef.InstaearnServiceSoapClient("InstaearnServiceSoap");
            //LocalInstaearnWebServiceRef.ClsRequest objClsRequest = new LocalInstaearnWebServiceRef.ClsRequest();

            OnlineInstaearnServiceRef.InstaearnServiceSoapClient objInstaearnServiceSoapClient = new OnlineInstaearnServiceRef.InstaearnServiceSoapClient("InstaearnServiceSoap1");
            OnlineInstaearnServiceRef.ClsRequest objClsRequest = new OnlineInstaearnServiceRef.ClsRequest();

            objClsRequest.iUserId = userId;
            objClsRequest.sProvideId = providerId;
            objClsRequest.sBundleId = bundleId;
            objClsRequest.iAppId = appId;
            objClsRequest.sRequestType = "App";
            objClsRequest.sServiceRequest = "FirstRequest";

            string sMessage = string.Empty;
   
            sMessage = objInstaearnServiceSoapClient.userRequest(objClsRequest);
            objInstaearnServiceSoapClient.as
            return Redirect("https://play.google.com/store/apps/details?id=" + bundleId);
        }
    }



It is working fine on localhost but throwing error on online server :

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond XXX.XXX.XX.XX.XX

Please suggest me some solution.

Thanks in advance
Posted
Comments
Sreekanth Mothukuru 16-Jun-15 9:30am    
Have you updated the web.config settings for the specific web service reference to reflect the changes applicable for production environment?

1 solution

I am assuming that you have referenced a valid service URL for online service that is hosted somewhere and "InstaearnServiceSoap1" points to the same.
If so, check your web config file too for configuration.
Alternatively check if the error is w.r.t cross origin issue.
Expose service headers in Web.config file of Service adding something like,

XML
<httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Headers" value="Content-Type" />
      <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
    </customHeaders>
  </httpProtocol>

under
<system.webServer>
section
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900