473,888 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(obje ct 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 8908
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(obje ct 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(obje ct 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(obje ct 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(t ype);
StringBuilder sb = new StringBuilder() ;
TextWriter writer = new StringWriter(sb );
serializer.Seri alize(writer,ob j);
writer.Close();
return sb.ToString();
}
public ArrayList DeserialiseObje ct(string root, System.Type type, string
strReader)
{
XmlRootAttribut e xmlRoot = new XmlRootAttribut e();
xmlRoot.Element Name = root;
XmlSerializer serializer = new XmlSerializer(t ype,xmlRoot);
XmlReader reader = new XmlTextReader(n ew StringReader(st rReader));
return (ArrayList)seri alizer.Deserial ize(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(obje ct 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.Element Name = 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,typeo f(ArrayList));

ArrayList objList1=
(ArrayList)Dese rialiseObject(" ArrayOfAnyType" ,typeof(ArrayLi st), strList1);

Eugen
"mo*********@ho tmail.com" wrote:
Hello Eugen,

could you please explain the following line
xmlRoot.Element Name = 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_ERR OR 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_bStartTran saction == true)
{
myTrans = m_SQLCommand.Tr ansaction;
if (m_bError == true)
{
myTrans.Rollbac k();
}
else
{
myTrans.Commit( );
}
}
m_SQLConnection .Close();
}

this.is_dispose d = true;
}

--function call inside service1.asmx.c s

try
{
using(DatabaseC lass dbObj = new DatabaseClass(m _strConnectionS tring,
true,"prApp_IsU serOwnerOfAnyPT G",false))
{
dbObj.BindStrin gParameter(strL ANID,"@User_LAN _ID");
dbObj.BindStrin gParameter(strO bjectName,"@Frm wk_code");

nCount = dbObj.BindStore dProcedureOutpu tIntParameterAn dExecute("@nCou nt");
}
}
catch (SoapException se)
{
throw(se);
}
catch(SqlExcept ion mySqlEx)
{
strErrorMessage = mySqlEx.Source + ":" + mySqlEx.Message ;
throwException( strErrorMessage ,"",mySqlEx.Num ber,m_strModule Name,m_strClass Name,
strFunctionName , 1243, 2, "Failed to update the database. Please contact the
system administrator") ;
}
catch(Exception myException)
{
strErrorMessage = myException.Sou rce + ":" + myException.Mes sage;
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*********@ho tmail.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_ERR OR 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
4432
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 = System.AppDomain.CurrentDomain.BaseDirectory() & "\WorkingFiles\" objImportExport = New BrainImportExport.BrainImportExport SendLoan = objImportExport.ImportLoanByLoan(data, filePath) objImportExport = Nothing
2
2069
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 ... If I instantiate the proxy class, I can set its Url property localhost.Sender oSender = new localhost.Sender(); // proxy clas oSender.Url = "http://server/webservice/s.asmx"
4
2747
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 also supported per the SOAP Spec, and from what I understand, .NET's implementation of WebServices, donot follow the standard, but instead shimmy this behavior by working with a strict request/response WSDL. So my question is - If I mark an int...
0
2833
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 that is to receive a System.IO.MemoryStream object and then deserialize it to retrieve the require information. When I try to make the call to the WebMethod from my web application the IDE is showing that it is not expecting a
22
25618
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 compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet = ws.VerifySku(cartSet)
1
1845
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 state the value as the parameter. Code in Csharp being developed in VS2005 for ASP.NET. Below is my webservice code. public DataSet findAAPAssessment(string assessmentID) {
9
3812
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 techniques are not feasible) The question is; Given that I have a Person object with a private set for id. What is the recommended approac in passing that object to the web service
4
3663
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 casts; In my asp page I have the following code which works fine HTTP.Open "GET","http://myserver/myService.asmx/LogPerson?ID=100", False
8
4404
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 function to format arraylist the way I want and calling it from button click event: Private Function formatarray(ByVal inarray As ArrayList, _
0
9961
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11182
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10886
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5824
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3252
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.