473,549 Members | 4,476 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 3442
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
7723
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
1783
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
12477
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...
0
941
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...
5
4861
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
6549
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
3773
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...
4
1628
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...
4
1501
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...
0
7526
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...
0
7455
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
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. ...
0
7962
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...
1
7480
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...
0
6050
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...
1
5373
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...
0
3504
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...
0
769
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...

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.