Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

I have a webservice where i am using a
VB
Session("BaseCurrency")
variable inside a method.

When the user call this Web Service Method which uses the
VB
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


Please help me resolve this issue.

Thanks

Varun Sareen
Posted
Updated 7-May-14 1:57am
v2
Comments
Sanket Saxena 7-May-14 7:45am    
paste your code
Varun Sareen 7-May-14 7:58am    
added.
Varun Sareen 7-May-14 7:58am    
Added
Sanket Saxena 7-May-14 7:59am    
where did you initialize the Session("BaseCurrency")?
Varun Sareen 7-May-14 8:07am    
Dear Sanket,

This is what i require. The Session("BaseCurrency") to be initialized the moment the WebService gets a hit.

Regards

Varun

1 solution

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