473,395 Members | 1,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,395 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 8875
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.