Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3934808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:45:29+00:00 2026-05-19T23:45:29+00:00

I am working with an ASMX service in ASP.NET/C#. My service returns proper data

  • 0

I am working with an ASMX service in ASP.NET/C#. My service returns proper data for some of my WebMethods, but not all. The interesting part is all of the WebMethods are very similar.

Here’s one that always returns data:

[WebMethod]
public AccountItem[] GetAllAccounts()
{
    AccountItem[] AccountItems = HttpContext.Current.Cache[AccountItemsCacheKey] as AccountItem[];
    if (AccountItems == null)
    {
        List<AccountItem> items = new List<AccountItem>();
        using (SqlManager sql = new SqlManager(SqlManager.GetSqlDbiConnectionString()))
        {
            using (SqlDataReader reader = sql.ExecuteReader("SELECT A.Account_Id, A.Customer_Id, C.Last_Name + ', ' + C.First_Name AS CustomerName, A.[Status], AT.Name AS AcctType, A.Employee_Id, A.Initial_Balance, A.Interest_Rate, '$'+CONVERT(varchar(50), A.Balance, 1) AS Balance FROM Account A JOIN Account_Type AT ON A.Account_Type_Id=AT.Account_Type_Id JOIN Customer C ON A.Customer_Id=C.Customer_Id WHERE [Status]=1"))
            {
                while (reader.Read())
                {
                    AccountItem item = new AccountItem();
                    item.AccountId = (int)reader["Account_Id"];
                    item.CustomerId = (int)reader["Customer_Id"];
                    item.CustomerName = (string)reader["CustomerName"];
                    item.AccountStatus = (bool)reader["Status"];
                    item.AccountType = (string)reader["AcctType"];
                    item.InitialBalance = (decimal)reader["Initial_Balance"];
                    item.InterestRate = (decimal)reader["Interest_Rate"];
                    item.Balance = (string)reader["Balance"];

                    items.Add(item);
                }
                reader.Close();
            }
        }
        HttpContext.Current.Cache.Add(AccountItemsCacheKey, items.ToArray(), null, DateTime.Now.AddMinutes(CacheDuration), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
        return items.ToArray();
    }
    else
    {
        return AccountItems;
    }
}

And here’s one that never returns data:

[WebMethod]
public TransactionItem[] GetAllTransactions()
{
    TransactionItem[] tranItems = HttpContext.Current.Cache[TransactionItemsCacheKey] as TransactionItem[];

    if (tranItems == null)
    {
        List<TransactionItem> items = new List<TransactionItem>();
        using (SqlManager sql = new SqlManager(SqlManager.GetSqlDbiConnectionString()))
        {
            using (SqlDataReader reader = sql.ExecuteReader("SELECT [Transaction_Id],[Account_Id],[Amount],[DateTime],[Comment],TT.[Name] AS [TransType],[Flagged],[Employee_Id],[Status] FROM [Transaction] T JOIN [Trans_Type] TT ON T.Trans_Type_Id=TT.Trans_Type_Id"))
            {
                while (reader.Read())
                {
                    TransactionItem item = new TransactionItem();
                    item.TransactionId = (int)reader["Transaction_Id"];
                    item.AccountId = (int)reader["Account_Id"];
                    item.Amount = (decimal)reader["Amount"];
                    item.Timestamp = (DateTime)reader["DateTime"];
                    item.Comment = (string)reader["Comment"];
                    item.TransType = (string)reader["TransType"];
                    item.Flagged = (bool)reader["Flagged"];
                    item.EmployeeId = (int)reader["Employee_Id"];
                    item.Status = (bool)reader["Status"];

                    items.Add(item);
                }
                reader.Close();
            }
        }
        HttpContext.Current.Cache.Add(TransactionItemsCacheKey, items.ToArray(), null, DateTime.Now.AddMinutes(CacheDuration), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
        return items.ToArray();
    }
    else
    {
        return tranItems;
    }
}

As you can see, they’re almost identical. The SQL queries for both return a ton of records, but only the GetAllAccounts() WebMethod actually returns that data back.

This is how I’m displaying the data passed back from GetAllAccounts(), which works fine:

@{
    Layout = "~/Shared/_Layout.cshtml";
    Page.Title = "Accounts";
    Page.Header = "BankSite Mobile - Accounts";
    var svc = IntranetService.GetAllAccounts();
}
 <div data-role="content">
        <ul data-role="listview" data-inset="true" data-theme="c">
            @foreach(var item in svc){
                <li>
                    <h3><a href="Product.cshtml?acctid=@item.AccountId">Account #@item.AccountId.ToString() (@item.AccountType)</a></h3>
                    <p>Customer: @item.CustomerName</p>
                    <p>Account Balance: @item.Balance</p>
                </li>
            }
       </ul>
  </div>

Yet, this doesn’t work fine, though it’s the almost the exact same code:

@{
    Layout = "~/Shared/_Layout.cshtml";
    Page.Title = "Customers";
    Page.Header = "BankSite Mobile - Customers";
    var svc = IntranetService.GetAllCustomers();
}
 <div data-role="content">
        <ul data-role="listview" data-inset="true" data-theme="c">
            @foreach(var item in svc){
                <li>
                    <h3><a href="Product.cshtml?acctid=@item.CustomerId">Account #@item.CustomerId.ToString() (@item.CustomerId)</a></h3>
                    <p>Customer: @item.CustomerId</p>
                    <p>Account Balance: @item.CustomerId</p>
                </li>
            }
       </ul>
  </div>

…So basically I’m baffled. I don’t understand why the data isn’t being returned as expected from the non-working WebMethod (GetAllCustomers()). What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:45:29+00:00Added an answer on May 19, 2026 at 11:45 pm

    I found the issue to be that some fields retrieved by the reader were null, and you can’t create a null string. The solution was essentially to use something like this for every item property:

    item.Amount = (reader["Amount"] != DBNull.value) ? (decimal)reader["Amount"] : 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery ajax call asp.net web service but it is not working.
I know every service we create (working with ASMX, .net 2.0) is attached with
I develop an asmx web service (i.e. ASP.NET 2.0). There's a piece of code
As we are working locally so our service link is: http://localhost:8012/webservice.asmx When we deploy
My website currently working in ASP.NET 1.1 Old Process In our database we have
I'm having trouble figuring out why my web service is not working correctly when
My use-case: I already have a working ASP.NET application I would like to implement
I'm writing Qt client for ASP.NET web service with FORMS based authentication. The service
In Ajax, i am using autocompleteExender in my asp.net application, i write the service
I am not able to call web service(asmx) from jQuery function. It is saying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.