Web服务中的问题 [英] Problem in web service

查看:39
本文介绍了Web服务中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的网络服务如下:

Hi,

I have a webservice like:

[WebMethod()]
       [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
       public string userRequest(ClsRequest objClsRequest)
       {
           string sMessage = string.Empty;
           ClsUserRequestProcess objClsUserRequestProcess = new ClsUserRequestProcess();

           sMessage = objClsUserRequestProcess.userRequestProcess(objClsRequest);

           return sMessage;
       }



---------------------------


---------------------------

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;
       }
   }





并通过添加服务引用和代码来完成MVC 4.0项目:





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

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);
        }
    }







它在localhost上工作正常,但抛出错误在线服务器上:



连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应XXX .XXX.XX.XX.XX



请给我一些解决方案。



提前致谢




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

推荐答案

我假设您已经为某个地方托管的在线服务引用了有效的服务URL,并且InstaearnServiceSoap1指向同一个。

如果是这样,请检查您的Web配置文件是否配置。

或者检查错误是否是交叉原始问题。

在服务的Web.config文件中公开服务头添加类似的东西,



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,

<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


这篇关于Web服务中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆