473,915 Members | 6,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can an object be passed to a WebMethod?

I have a C# dataclass object that I would like to pass to a Web Service
WebMethod, modify some strings, and return it to the caller but I am getting
compiler errors in the client. I'm not an expert on Web Services and am
wondering if what I am attempting is even doable?

Even this simple test generates the error:

From the Web Service:

[WebMethod]
public StringBuilder ProcessTsrOrder (StringBuilder sb)
{
return sb.Append("Hell o World!");
}

From the test client:

private void btnTest_Click(o bject sender, EventArgs e)
{
StringBuilder sb = new StringBuilder() ;
TSRWS.TSRTxns txns = new TSRWS.TSRTxns() ;
sb = txns.ProcessTsr Order(sb); //<<< compiler error here
txtMessage.Text = sb.ToString();
}

Error 1 The best overloaded method match for
'WebServiceTest .TSRWS.TSRTxns. ProcessTsrOrder (WebServiceTest .TSRWS.StringBu ilder)'
has some invalid arguments C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.St ringBuilder' to
'WebServiceTest .TSRWS.StringBu ilder' C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 39
WebServiceTest
Feb 4 '06 #1
5 3456
Ray,

Yes, you can pass objects between web methods. However, I wouldn't
recommend passing something like a StringBuilder. I would just pass a
string. In reality, you are gaining nothing from passing the StringBuilder.
Your method is taking a StringBuilder and returning one. Instead, just pass
strings.

The reason you are getting this error is that the WSDL is exposing a
type definition for StringBuilder, and when you create a proxy to that
method, you are getting that definition of StringBuilder, not the one that
is exposed in the framework. It is for this reason that you can not perform
the cast.

You could use the StringBuilder type that is exposed by the web service,
but that doesn't gain you anything either, since that will only expose
properties, and not the methods on the StringBuilder.

You should not expect to pass functional objects around through web
services. Rather, if you want to send objects around, you should think of
sending pieces of information around, which have no inherent methods on them
to perform operations on them.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Ray Stevens" <nf*@nospam.com > wrote in message
news:Oo******** ******@TK2MSFTN GP14.phx.gbl...
I have a C# dataclass object that I would like to pass to a Web Service
WebMethod, modify some strings, and return it to the caller but I am
getting compiler errors in the client. I'm not an expert on Web Services
and am wondering if what I am attempting is even doable?

Even this simple test generates the error:

From the Web Service:

[WebMethod]
public StringBuilder ProcessTsrOrder (StringBuilder sb)
{
return sb.Append("Hell o World!");
}

From the test client:

private void btnTest_Click(o bject sender, EventArgs e)
{
StringBuilder sb = new StringBuilder() ;
TSRWS.TSRTxns txns = new TSRWS.TSRTxns() ;
sb = txns.ProcessTsr Order(sb); //<<< compiler error here
txtMessage.Text = sb.ToString();
}

Error 1 The best overloaded method match for
'WebServiceTest .TSRWS.TSRTxns. ProcessTsrOrder (WebServiceTest .TSRWS.StringBu ilder)'
has some invalid arguments C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.St ringBuilder' to
'WebServiceTest .TSRWS.StringBu ilder' C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 39
WebServiceTest

Feb 4 '06 #2
Nicholas is right, of course, about the StringBuilder class. This might help
you understand what you can pass to a web service and how.

http://www.dalepreston.com/Blog/2005...-from-web.html
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Ray Stevens" wrote:
I have a C# dataclass object that I would like to pass to a Web Service
WebMethod, modify some strings, and return it to the caller but I am getting
compiler errors in the client. I'm not an expert on Web Services and am
wondering if what I am attempting is even doable?

Even this simple test generates the error:

From the Web Service:

[WebMethod]
public StringBuilder ProcessTsrOrder (StringBuilder sb)
{
return sb.Append("Hell o World!");
}

From the test client:

private void btnTest_Click(o bject sender, EventArgs e)
{
StringBuilder sb = new StringBuilder() ;
TSRWS.TSRTxns txns = new TSRWS.TSRTxns() ;
sb = txns.ProcessTsr Order(sb); //<<< compiler error here
txtMessage.Text = sb.ToString();
}

Error 1 The best overloaded method match for
'WebServiceTest .TSRWS.TSRTxns. ProcessTsrOrder (WebServiceTest .TSRWS.StringBu ilder)'
has some invalid arguments C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.St ringBuilder' to
'WebServiceTest .TSRWS.StringBu ilder' C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 39
WebServiceTest

Feb 5 '06 #3
The link helped with my immediate problem, but then I encountered another.
We are using a layered architecture. The web service calls down to a
Business Logic Layer which, in turn, calls down to a Data Access Layer. With
the information provided in the link, I am now able to reference the data
class in the client and successfully call the Web Service. However, I am
unable to pass it down to the BLL/DAL layers for the same reason. (I.e., I
get the identical compile error as before)

"Dale" <da******@nospa m.nospam> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
Nicholas is right, of course, about the StringBuilder class. This might
help
you understand what you can pass to a web service and how.

http://www.dalepreston.com/Blog/2005...-from-web.html
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Ray Stevens" wrote:
I have a C# dataclass object that I would like to pass to a Web Service
WebMethod, modify some strings, and return it to the caller but I am
getting
compiler errors in the client. I'm not an expert on Web Services and am
wondering if what I am attempting is even doable?

Even this simple test generates the error:

From the Web Service:

[WebMethod]
public StringBuilder ProcessTsrOrder (StringBuilder sb)
{
return sb.Append("Hell o World!");
}

From the test client:

private void btnTest_Click(o bject sender, EventArgs e)
{
StringBuilder sb = new StringBuilder() ;
TSRWS.TSRTxns txns = new TSRWS.TSRTxns() ;
sb = txns.ProcessTsr Order(sb); //<<< compiler error here
txtMessage.Text = sb.ToString();
}

Error 1 The best overloaded method match for
'WebServiceTest .TSRWS.TSRTxns. ProcessTsrOrder (WebServiceTest .TSRWS.StringBu ilder)'
has some invalid arguments C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.St ringBuilder' to
'WebServiceTest .TSRWS.StringBu ilder' C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 39
WebServiceTest

Feb 7 '06 #4
Are the business layer and data layer on the same machine and in the same
application as the web service?

If so, it is still likely to be a namespace issue. The same techniques
would still work.

This link may help, too:

http://msdn.microsoft.com/library/de...assemblies.asp

--
Dale Preston
MCAD C#
MCSE, MCDBA
"Ray Stevens" wrote:
The link helped with my immediate problem, but then I encountered another.
We are using a layered architecture. The web service calls down to a
Business Logic Layer which, in turn, calls down to a Data Access Layer. With
the information provided in the link, I am now able to reference the data
class in the client and successfully call the Web Service. However, I am
unable to pass it down to the BLL/DAL layers for the same reason. (I.e., I
get the identical compile error as before)

"Dale" <da******@nospa m.nospam> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
Nicholas is right, of course, about the StringBuilder class. This might
help
you understand what you can pass to a web service and how.

http://www.dalepreston.com/Blog/2005...-from-web.html
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Ray Stevens" wrote:
I have a C# dataclass object that I would like to pass to a Web Service
WebMethod, modify some strings, and return it to the caller but I am
getting
compiler errors in the client. I'm not an expert on Web Services and am
wondering if what I am attempting is even doable?

Even this simple test generates the error:

From the Web Service:

[WebMethod]
public StringBuilder ProcessTsrOrder (StringBuilder sb)
{
return sb.Append("Hell o World!");
}

From the test client:

private void btnTest_Click(o bject sender, EventArgs e)
{
StringBuilder sb = new StringBuilder() ;
TSRWS.TSRTxns txns = new TSRWS.TSRTxns() ;
sb = txns.ProcessTsr Order(sb); //<<< compiler error here
txtMessage.Text = sb.ToString();
}

Error 1 The best overloaded method match for
'WebServiceTest .TSRWS.TSRTxns. ProcessTsrOrder (WebServiceTest .TSRWS.StringBu ilder)'
has some invalid arguments C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.St ringBuilder' to
'WebServiceTest .TSRWS.StringBu ilder' C:\Documents and Settings\bmatto x\My
Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 39
WebServiceTest


Feb 8 '06 #5
They are on the same machine but the same application. Each layer is in a
separate project.

BTW, this does not appear to be a problem with .NET 1.1 for some reason. In
fact, I am even able to use ref in the Web Service call, make changes in the
web service, and reflect them in the client. Something seems to have been
drastically changed with .NET 2.0.

"Dale" <da******@nospa m.nospam> wrote in message
news:84******** *************** ***********@mic rosoft.com...
Are the business layer and data layer on the same machine and in the same
application as the web service?

If so, it is still likely to be a namespace issue. The same techniques
would still work.

This link may help, too:

http://msdn.microsoft.com/library/de...assemblies.asp

--
Dale Preston
MCAD C#
MCSE, MCDBA
"Ray Stevens" wrote:
The link helped with my immediate problem, but then I encountered
another.
We are using a layered architecture. The web service calls down to a
Business Logic Layer which, in turn, calls down to a Data Access Layer.
With
the information provided in the link, I am now able to reference the data
class in the client and successfully call the Web Service. However, I am
unable to pass it down to the BLL/DAL layers for the same reason. (I.e.,
I
get the identical compile error as before)

"Dale" <da******@nospa m.nospam> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
> Nicholas is right, of course, about the StringBuilder class. This
> might
> help
> you understand what you can pass to a web service and how.
>
> http://www.dalepreston.com/Blog/2005...-from-web.html
> --
> Dale Preston
> MCAD C#
> MCSE, MCDBA
>
>
> "Ray Stevens" wrote:
>
>> I have a C# dataclass object that I would like to pass to a Web
>> Service
>> WebMethod, modify some strings, and return it to the caller but I am
>> getting
>> compiler errors in the client. I'm not an expert on Web Services and
>> am
>> wondering if what I am attempting is even doable?
>>
>> Even this simple test generates the error:
>>
>> From the Web Service:
>>
>> [WebMethod]
>> public StringBuilder ProcessTsrOrder (StringBuilder sb)
>> {
>> return sb.Append("Hell o World!");
>> }
>>
>> From the test client:
>>
>> private void btnTest_Click(o bject sender, EventArgs e)
>> {
>> StringBuilder sb = new StringBuilder() ;
>> TSRWS.TSRTxns txns = new TSRWS.TSRTxns() ;
>> sb = txns.ProcessTsr Order(sb); //<<< compiler error here
>> txtMessage.Text = sb.ToString();
>> }
>>
>> Error 1 The best overloaded method match for
>> 'WebServiceTest .TSRWS.TSRTxns. ProcessTsrOrder (WebServiceTest .TSRWS.StringBu ilder)'
>> has some invalid arguments C:\Documents and Settings\bmatto x\My
>> Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 18
>> WebServiceTest
>> Error 2 Argument '1': cannot convert from 'System.Text.St ringBuilder'
>> to
>> 'WebServiceTest .TSRWS.StringBu ilder' C:\Documents and
>> Settings\bmatto x\My
>> Documents\Visua l Studio\Projects \TSRWS\WebServi ceTest\Form1.cs 25 39
>> WebServiceTest
>>
>>
>>


Feb 8 '06 #6

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

Similar topics

12
7828
by: Mark Rae | last post by:
Hi, Can anyone please tell me how to convert an unserializeable object say, a System.Web.Mail.MailMessage object, to a byte array and then convert the byte array to a Base64 string? Any assistance gratefully received. Best regards,
0
1797
by: Henke | last post by:
Hi I have a webservice that should return a result object, like this: public class Result { private object data; private int status; public object Data { get{return data;}
6
12500
by: rlcavebmg | last post by:
I am new to Web Services and .NET development, and I have a question. I am writing a service that will create a bitmap image and return it to the client. First, I wrote a method that looked like this: public System.Drawing.Bitmap CreateImage() {...} When I tried to create the web reference in my client program, I got an error message stating that the System.Drawing.Bitmap object could not be serialized because it does not have a...
0
953
by: Martin | last post by:
Hi All, I am writing a WS to Web-enable a 3-rd party .Net custome object(myObj), which does three things: 1. Make a socket connection to Server - myObj.open() 2. Send a msg to the Server - myObj.send() 3. Close socket connection - myObj.close() Because of some reasons I have to do these three action in 3 different webMethod(openConnectionWS();sendMsgWS();closeConnectionWS()), therefore, I
5
4882
by: Joseph Geretz | last post by:
Here's my first attempt at DIME (code below signature). I'ts basically straight out of Microsoft's online sample: For some reason, the statement respContext.Attachments.Add(dimeAttach); trips the following error: Object reference not set to an instance of an object.
2
6579
by: SP | last post by:
Hello All, I have a web method in a web service as follows: public SqlDataReader Display_test_data() { string connectionInfo = ConfigurationSettings.AppSettings;
9
3817
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
1642
by: =?Utf-8?B?QWw=?= | last post by:
Hello, I'm writing a service using VS2005 and C#. I've found that only the objects used as parameters in WebMethods get exported to proxy dlls and the Service Description. I'd like my service clients to be able to use the objects I've defined in messages to the service and send them as "object" parameters or as embeded items in other objects. I can work around the problem by declaring all of the objects as public members of a dummy...
4
1519
by: dan655t | last post by:
Hello, I've come here to get some advise from the experts. Currently I am tasked with modifying a web service that currently supports one product to support multiple products. It needs to be backwards compatible so other products still work with the same method calls and the new products need to have methods with the same names, but different logic. Currently we keep some credential information from the client that consumes the...
0
10039
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
11354
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...
0
10923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9732
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
8100
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
7256
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
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4778
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.