473,379 Members | 974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

passing a System.object parameter to a webservice.

Hi,
I'm trying to pass values of different data-types to a web-service. I
thought it would be easier to box these values and pass them as a
System.object parameter, like

[webmethod]
public void webmethod1(object a)

where a can be of type string, DateTime, float, etc..

Now, within this webmethod, I need to know the DataType of the object
received.

My question is, does the XML serialization preserve the datatype of the
System.object parameter. If not, I will have to pass the associated .NET
DataType as a second parameter.

Any suggestions would be greatly apprecaited.

Thank you,
Ravi
Jan 24 '07 #1
8 8873
Ravi,

From my understanding, you want to pass a variety of types and you are
trying to
box inside a custom object. These types are defined as individual proerties
of the custom object like the following
Public Class

Public Property CustomDate as DataTime
Public Propert Name as String
Public Property CostPrice as Float

End Class

XXL Serialization preserves basic types. I mean like string, integer, float
etc.
I'm not sure whether it will preserve DateTime.Just explore it.
It's a good idea to box (wrap) these parameters inside objects and pass
back & forth between services. This becomes really handy if you are trying
to interoperate with J2EE

To conclude the Passing Custom objects is not a restriction in WebServices
Thanks & Regards,
Mark Nelson
"Ravi" wrote:
Hi,
I'm trying to pass values of different data-types to a web-service. I
thought it would be easier to box these values and pass them as a
System.object parameter, like

[webmethod]
public void webmethod1(object a)

where a can be of type string, DateTime, float, etc..

Now, within this webmethod, I need to know the DataType of the object
received.

My question is, does the XML serialization preserve the datatype of the
System.object parameter. If not, I will have to pass the associated .NET
DataType as a second parameter.

Any suggestions would be greatly apprecaited.

Thank you,
Ravi
Jan 25 '07 #2

Thank you Mark.

"Mark Nelson" wrote:
Ravi,

From my understanding, you want to pass a variety of types and you are
trying to
box inside a custom object. These types are defined as individual proerties
of the custom object like the following
Public Class

Public Property CustomDate as DataTime
Public Propert Name as String
Public Property CostPrice as Float

End Class

XXL Serialization preserves basic types. I mean like string, integer, float
etc.
I'm not sure whether it will preserve DateTime.Just explore it.
It's a good idea to box (wrap) these parameters inside objects and pass
back & forth between services. This becomes really handy if you are trying
to interoperate with J2EE

To conclude the Passing Custom objects is not a restriction in WebServices
Thanks & Regards,
Mark Nelson
"Ravi" wrote:
Hi,
I'm trying to pass values of different data-types to a web-service. I
thought it would be easier to box these values and pass them as a
System.object parameter, like

[webmethod]
public void webmethod1(object a)

where a can be of type string, DateTime, float, etc..

Now, within this webmethod, I need to know the DataType of the object
received.

My question is, does the XML serialization preserve the datatype of the
System.object parameter. If not, I will have to pass the associated .NET
DataType as a second parameter.

Any suggestions would be greatly apprecaited.

Thank you,
Ravi
Jan 26 '07 #3
Ravi,

If my answer was useful, please press the 'was this post helpful to you' as
'Yes'.
--
Thanks & Regards,
Mark Nelson
"Ravi" wrote:
>
Thank you Mark.

"Mark Nelson" wrote:
Ravi,

From my understanding, you want to pass a variety of types and you are
trying to
box inside a custom object. These types are defined as individual proerties
of the custom object like the following
Public Class

Public Property CustomDate as DataTime
Public Propert Name as String
Public Property CostPrice as Float

End Class

XXL Serialization preserves basic types. I mean like string, integer, float
etc.
I'm not sure whether it will preserve DateTime.Just explore it.
It's a good idea to box (wrap) these parameters inside objects and pass
back & forth between services. This becomes really handy if you are trying
to interoperate with J2EE

To conclude the Passing Custom objects is not a restriction in WebServices
Thanks & Regards,
Mark Nelson
"Ravi" wrote:
Hi,
I'm trying to pass values of different data-types to a web-service. I
thought it would be easier to box these values and pass them as a
System.object parameter, like
>
[webmethod]
public void webmethod1(object a)
>
where a can be of type string, DateTime, float, etc..
>
Now, within this webmethod, I need to know the DataType of the object
received.
>
My question is, does the XML serialization preserve the datatype of the
System.object parameter. If not, I will have to pass the associated .NET
DataType as a second parameter.
>
Any suggestions would be greatly apprecaited.
>
Thank you,
Ravi
Jan 29 '07 #4
Hi Ravi,

As Mark was saying, basic data types are serialized automatically when
passing them as parameters in a web service method call. What I used to have
dificulties in the past is to pass more complex types as is the ArrayList
data type.

I had to write couple of methods to be able pass this data type in a web
method as follows:
public string SerializeObject(ArrayList obj, System.Type type)
{
XmlSerializer serializer = new XmlSerializer(type);
StringBuilder sb = new StringBuilder();
TextWriter writer = new StringWriter(sb);
serializer.Serialize(writer,obj);
writer.Close();
return sb.ToString();
}
public ArrayList DeserialiseObject(string root, System.Type type, string
strReader)
{
XmlRootAttribute xmlRoot = new XmlRootAttribute();
xmlRoot.ElementName = root;
XmlSerializer serializer = new XmlSerializer(type,xmlRoot);
XmlReader reader = new XmlTextReader(new StringReader(strReader));
return (ArrayList)serializer.Deserialize(reader);
}
Hope that helps.
Best regards,
Eugen
"Mark Nelson" wrote:
Ravi,

If my answer was useful, please press the 'was this post helpful to you' as
'Yes'.
--
Thanks & Regards,
Mark Nelson
"Ravi" wrote:

Thank you Mark.

"Mark Nelson" wrote:
Ravi,
>
From my understanding, you want to pass a variety of types and you are
trying to
box inside a custom object. These types are defined as individual proerties
of the custom object like the following
>
>
Public Class
>
Public Property CustomDate as DataTime
Public Propert Name as String
Public Property CostPrice as Float
>
End Class
>
XXL Serialization preserves basic types. I mean like string, integer, float
etc.
I'm not sure whether it will preserve DateTime.Just explore it.
>
>
It's a good idea to box (wrap) these parameters inside objects and pass
back & forth between services. This becomes really handy if you are trying
to interoperate with J2EE
>
To conclude the Passing Custom objects is not a restriction in WebServices
Thanks & Regards,
Mark Nelson
>
>
"Ravi" wrote:
>
Hi,
I'm trying to pass values of different data-types to a web-service. I
thought it would be easier to box these values and pass them as a
System.object parameter, like

[webmethod]
public void webmethod1(object a)

where a can be of type string, DateTime, float, etc..

Now, within this webmethod, I need to know the DataType of the object
received.

My question is, does the XML serialization preserve the datatype of the
System.object parameter. If not, I will have to pass the associated .NET
DataType as a second parameter.

Any suggestions would be greatly apprecaited.

Thank you,
Ravi
Jan 31 '07 #5
Hello Eugen,

could you please explain the following line
xmlRoot.ElementName = root

i don't know which root is this.

i am assuming strReader is the serialized string you returned with the
SerializeObject function. am i right or wrong?

thanks beforehand
Jorge

Mar 7 '07 #6
Hi Jorge,

Sorry, haven't read thes posts for some time:

strList1 = SerializeObject(objList1,typeof(ArrayList));

ArrayList objList1=
(ArrayList)DeserialiseObject("ArrayOfAnyType",type of(ArrayList), strList1);

Eugen
"mo*********@hotmail.com" wrote:
Hello Eugen,

could you please explain the following line
xmlRoot.ElementName = root

i don't know which root is this.

i am assuming strReader is the serialized string you returned with the
SerializeObject function. am i right or wrong?

thanks beforehand
Jorge

Mar 15 '07 #7
Hello Eugen,

i got the serialization and deserialization to work Thanks.

Now i need to implement a transaction. i think i will not be able to
accomplish the following using web services.
Scenario:
the code behind web_page_1 Calls webservice_1 and starts transaction.
the results of webservice_1 are used by webservice_2.
if THERE_IS_AN_ERROR then
rollback transaction
else
commit transaction
the results of webservice2 are displayed in web_page_2.

thanks for any input.
Jorge

Mar 20 '07 #8
Hi Jorge,

There is no problem with creating a transaction from a web service,
commiting it or rolling it back. I am doing this using a database class I
have created. The constructor of this class has a parameter for stating a
transaction. I am using the "using" keyword when creating a new instance of
that class. Whenever this object goes out of scope, I have code in the
Dispose method to commit ot rollback the transaction based on a flag that
tells me if the statement executes successfully or not.

Something like that:
protected virtual void Dispose(bool disposing)
{
if(!is_disposed)
{
if(disposing)
{
}

if(m_bStartTransaction == true)
{
myTrans = m_SQLCommand.Transaction;
if (m_bError == true)
{
myTrans.Rollback();
}
else
{
myTrans.Commit();
}
}
m_SQLConnection.Close();
}

this.is_disposed = true;
}

--function call inside service1.asmx.cs

try
{
using(DatabaseClass dbObj = new DatabaseClass(m_strConnectionString,
true,"prApp_IsUserOwnerOfAnyPTG",false))
{
dbObj.BindStringParameter(strLANID,"@User_LAN_ID") ;
dbObj.BindStringParameter(strObjectName,"@Frmwk_co de");

nCount = dbObj.BindStoredProcedureOutputIntParameterAndExec ute("@nCount");
}
}
catch (SoapException se)
{
throw(se);
}
catch(SqlException mySqlEx)
{
strErrorMessage = mySqlEx.Source + ":" + mySqlEx.Message;
throwException(strErrorMessage,"",mySqlEx.Number,m _strModuleName,m_strClassName,
strFunctionName, 1243, 2, "Failed to update the database. Please contact the
system administrator");
}
catch(Exception myException)
{
strErrorMessage = myException.Source + ":" + myException.Message;
throwException(strErrorMessage, "", 0, m_strModuleName, m_strClassName,
strFunctionName, 1243, 2, "Failed to update the database. Please contact the
system administrator");
}
finally
{
}

Your intention is to use two separate web services to work in the context of
the same transaction in the database?

Eugen

"mo*********@hotmail.com" wrote:
Hello Eugen,

i got the serialization and deserialization to work Thanks.

Now i need to implement a transaction. i think i will not be able to
accomplish the following using web services.
Scenario:
the code behind web_page_1 Calls webservice_1 and starts transaction.
the results of webservice_1 are used by webservice_2.
if THERE_IS_AN_ERROR then
rollback transaction
else
commit transaction
the results of webservice2 are displayed in web_page_2.

thanks for any input.
Jorge

Mar 21 '07 #9

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

Similar topics

0
by: gagans | last post by:
Hi My web service has a method which accepts byte array as parameter. <WebMethod()> _ Public Function SendLoan(ByVal data As Byte()) As String Dim filePath As String filePath =...
2
by: Stan | last post by:
I need to change the Url property in a web service proxy class in a generic way. The proxy class looks like this public class Sender : System.Web.Services.Protocols.SoapHttpClientProtocol ... ...
4
by: Sahil Malik [MVP] | last post by:
Okay so now I understand (surprised though) - that WebServices can indeed pass ByRef/ref parameters. All I have to do is mark an integer parameter of a WebMethod as "ref". Funnily enough, this is...
0
by: Steve | last post by:
I am using an XMLSerializer to create an xml object of a class in a web application. I am then using an XMLWriter to place this into a memory stream. No problems so far. I have a web service...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
1
by: Deecrypt | last post by:
Hi, Passing a string parameter to a webservice to get the dataset generated as the result, seems to give me an error suggesting that no parameter is being passed. However it works if I explicitly...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
4
by: MarkusJNZ | last post by:
Hi, I am trying to pass an number from a classic asp webpage to a .NET webservice. Because my C# webservice expects an integer and classic ASP uses variants I keep getting problems with object...
8
by: amazon | last post by:
I have a following structure that I am using with array list: Private Structure arrayliststruct Public Name As String Public value As String Public type As String End Structure and following...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.