471,617 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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("Hello World!");
}

From the test client:

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

Error 1 The best overloaded method match for
'WebServiceTest.TSRWS.TSRTxns.ProcessTsrOrder(WebS erviceTest.TSRWS.StringBuilder)'
has some invalid arguments C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.StringBuilder' to
'WebServiceTest.TSRWS.StringBuilder' C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 39
WebServiceTest
Feb 4 '06 #1
5 3336
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.com

"Ray Stevens" <nf*@nospam.com> wrote in message
news:Oo**************@TK2MSFTNGP14.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("Hello World!");
}

From the test client:

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

Error 1 The best overloaded method match for
'WebServiceTest.TSRWS.TSRTxns.ProcessTsrOrder(WebS erviceTest.TSRWS.StringBuilder)'
has some invalid arguments C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.StringBuilder' to
'WebServiceTest.TSRWS.StringBuilder' C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\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("Hello World!");
}

From the test client:

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

Error 1 The best overloaded method match for
'WebServiceTest.TSRWS.TSRTxns.ProcessTsrOrder(WebS erviceTest.TSRWS.StringBuilder)'
has some invalid arguments C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.StringBuilder' to
'WebServiceTest.TSRWS.StringBuilder' C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\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******@nospam.nospam> wrote in message
news:F1**********************************@microsof t.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("Hello World!");
}

From the test client:

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

Error 1 The best overloaded method match for
'WebServiceTest.TSRWS.TSRTxns.ProcessTsrOrder(WebS erviceTest.TSRWS.StringBuilder)'
has some invalid arguments C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.StringBuilder' to
'WebServiceTest.TSRWS.StringBuilder' C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\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******@nospam.nospam> wrote in message
news:F1**********************************@microsof t.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("Hello World!");
}

From the test client:

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

Error 1 The best overloaded method match for
'WebServiceTest.TSRWS.TSRTxns.ProcessTsrOrder(WebS erviceTest.TSRWS.StringBuilder)'
has some invalid arguments C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 18
WebServiceTest
Error 2 Argument '1': cannot convert from 'System.Text.StringBuilder' to
'WebServiceTest.TSRWS.StringBuilder' C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\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******@nospam.nospam> wrote in message
news:84**********************************@microsof t.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******@nospam.nospam> wrote in message
news:F1**********************************@microsof t.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("Hello World!");
>> }
>>
>> From the test client:
>>
>> private void btnTest_Click(object sender, EventArgs e)
>> {
>> StringBuilder sb = new StringBuilder();
>> TSRWS.TSRTxns txns = new TSRWS.TSRTxns();
>> sb = txns.ProcessTsrOrder(sb); //<<< compiler error here
>> txtMessage.Text = sb.ToString();
>> }
>>
>> Error 1 The best overloaded method match for
>> 'WebServiceTest.TSRWS.TSRTxns.ProcessTsrOrder(WebS erviceTest.TSRWS.StringBuilder)'
>> has some invalid arguments C:\Documents and Settings\bmattox\My
>> Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 18
>> WebServiceTest
>> Error 2 Argument '1': cannot convert from 'System.Text.StringBuilder'
>> to
>> 'WebServiceTest.TSRWS.StringBuilder' C:\Documents and
>> Settings\bmattox\My
>> Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 25 39
>> WebServiceTest
>>
>>
>>


Feb 8 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by rlcavebmg | last post: by
9 posts views Thread by Greger | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.