473,507 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebService out parameter returning incorrect value

If passing a DataSet to a web method for update using ADO.NET and the
update fails, the parameter list may get corrupt.
The following code example consists of a Web Service and a consumer
console application, both written in C# using VS.NET.

A tiny MSSQL database is required to run the example:
create table test1 (id numeric(1) unique)

The console app creates a DataSet and passes it to the Web Service for
update. The first execution is OK but subsequent executions will
correctly cause a UNIQUE constrain violation. The err parameter gets
set to 1 BUT UPON RETURN TO THE CALLER IT HAS THE VALUE 0.

I am aware that removing the "ref" attribute on the DataSet parameter
will solve the problem in this case but still, it seems like a bug to
me.
Console Application:
====================

using System;
using System.Data;
using System.Diagnostics;

namespace BugReportConsumer
{

class Class1
{

[STAThread]
static void Main(string[] args)
{
localhost.Service1 service = new
BugReportConsumer.localhost.Service1();

int err;
string msg;

DataSet ds = new DataSet();
DataTable t = ds.Tables.Add("test1");
t.Columns.Add("id",System.Type.GetType("System.Int 32"));
object[] row = {1};
t.Rows.Add(row);

service.UpdateData(ref ds, out err, out msg);
Trace.WriteLine("Return: "+err.ToString() + " Msg: " + msg);
}
}
}
Web Service:
============

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace BugReport
{
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services
Designer
InitializeComponent();
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

[WebMethod]
public int UpdateData(ref DataSet ds, out int err, out string
errMsg)
{
int nRows = 0;
err = 0;
errMsg = "";

try
{
SqlConnection conn = new SqlConnection("server=localhost" +
";database=testdb" +
";user id=sa" +
";password=secret");

string stmt = "SELECT * FROM test1";
SqlDataAdapter da = new SqlDataAdapter(stmt, conn);

SqlCommandBuilder cmd = new SqlCommandBuilder(da);

nRows = da.Update(ds,"test1");

}
catch (Exception e)
{
err = 1;
errMsg = e.Message;
return 0;
}

return nRows;
}
}
}
Nov 15 '05 #1
0 6126

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3631
by: Srini | last post by:
I have written two simple webservice functions and trying to consume them through a client piece. Both the webservice functions have similar signature....
12
4103
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
0
1225
jeffbroodwar
by: jeffbroodwar | last post by:
hi, i need help about consuming webservice created in java with vb6. i've created the webservice in netbeans with sun java server bundle and used MS Soap toolkit 3.0 on the client side. i've...
2
2778
jeffbroodwar
by: jeffbroodwar | last post by:
hi, i need help about consuming webservice created in java with vb6. i've created the webservice in netbeans with sun java server bundle and used MS Soap toolkit 3.0 on the client side. i've...
0
1218
jeffbroodwar
by: jeffbroodwar | last post by:
hi, i need help about consuming webservice created in java with vb6. i've created the webservice in netbeans with sun java server bundle and used MS Soap toolkit 3.0 on the client side. i've...
5
5531
jeffbroodwar
by: jeffbroodwar | last post by:
hi, i need help about consuming webservice created in java with vb6. i've created the webservice in netbeans with sun java server bundle and used MS Soap toolkit 3.0 on the client side. i've...
0
2347
by: TraceyAnnison | last post by:
I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis. We have a Java project built with the Spring framework, in order to...
4
7128
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.