如何在WebService方法之间使用Session变量? [英] how to Use Session variable between WebService method?

查看:162
本文介绍了如何在WebService方法之间使用Session变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我有一个网络服务,我正在使用

Dear Friends,

I have a webservice where i am using a

Session("BaseCurrency")

方法中的变量。



当用户调用此Web服务方法时,该方法使用

variable inside a method.

When the user call this Web Service Method which uses the

Session("BaseCurrency")

变量然后发生错误: -



对象引用未设置为实例对象。



我知道这个变量值没有被初始化,这就是为什么会出现这个错误,但我必须使用我的方法中的这个变量值因为不同公司的价值不同。



用户可以为任何公司使用此网络服务,也可以使用基础货币对于不同的公司可能会有所不同。



请找到以下代码: -



variable then an error occurs:-

"Object reference not set to an instance of an object.".

I am aware that this variable value is not initialized that is why this error is coming but i have to use this variable value in my method as the value for different companies are different.

The user can consume this webservice for any company and also the Base Currency could be different for different company.

Please find the code below:-

Public Class MISService
    Inherits System.Web.Services.WebService 
    <WebMethod()> _
    Public Function InsertMIS(ByVal strMis1 As String, ByVal strMis2 As String, ByVal strMis3 As String, ByVal pardoc As String, ByVal csid As String) As Object
        Dim objMIS As New Prj_misrgp.cls_misrgp
        Try
            Dim strMis As String = strMis1 + strMis2 + strMis3
            strMis = strMis.Replace("APPglcost", Application("Glcostset"))
            strMis = strMis.Replace("APPcurcost", Application("curcostset"))
 
            Return objMIS.save(strMis, pardoc, "MIS", "4.3.3", csid, "", "", Session("BaseCurrency"))
        Catch ex As Exception
            Return ex.Message
        Finally
            objMIS = Nothing
        End Try
End Class
    End Function





请帮我解决这个问题。



谢谢



Varun Sareen



Please help me resolve this issue.

Thanks

Varun Sareen

推荐答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace MySessionEnabledWebService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod(EnableSession = true)]
        public int GetPerUserClickCount()
        {
            int count;
            if (Session["ConnectCount"] == null)
                count = 1;
            else
                count = (int)Session["ConnectCount"] + 1;
            Session["ConnectCount"] = count;
            return count;
        }
    }
}


这篇关于如何在WebService方法之间使用Session变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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