Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Why am I getting a compile error on a referenced Web Service parameter

Reply
Thread Tools

Why am I getting a compile error on a referenced Web Service parameter

 
 
Ray Stevens
Guest
Posts: n/a
 
      02-02-2006
I have a simple method that is using a complex data class created by a
mainframe interface code generator. I compiled this into a Business Entities
project and referenced it in both the Web Service and the client, so it
should be identical in both.

A sample abrivation of the class is of the following form:

namespace SoftwareAG.EntireX.NETWrapper.Generated.tsrsubi1.G roups
{
public class Tsrsubi1
{
public class Xormsga2
{
[SendAs(IdlType.A, Length=3f, Trim=true)]public string
environment ;
[SendAs(IdlType.A, Length=3f, Trim=true)]public string sourceApp
;
[SendAs(IdlType.A, Length=8f, Trim=true)]public string
destinationApp ;
// etc
public class OrderHeader
{
[SendAs(IdlType.A, Length=12f, Trim=true)]public string
orderNo ;
[SendAs(IdlType.A, Length=5f, Trim=true)]public string
custId ;
[SendAs(IdlType.A, Length=7f, Trim=true)]public string
unitId ;
// etc
}
// etc
}
}
}

The test Web Service looks as follows:

using SoftwareAG.EntireX.NETWrapper.Generated.tsrsubi1.G roups;

[WebService(Namespace = "http://company.com/webservices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TSRTxns : System.Web.Services.WebService
{
[WebMethod]
public void ProcessTsrOrder(ref Tsrsubi1.Xormsga2 etx)
{
TSRBLL bll = new TSRBLL();
bll.ProcessTsrOrder(ref etx);
}
}

The test client is referencing the web service as:

using SoftwareAG.EntireX.NETWrapper.Generated.tsrsubi1.G roups;

namespace WebServiceTest
{
public partial class Form1 : Form
{
private void btnTest_Click(object sender, EventArgs e)
{
Tsrsubi1.Xormsga2 etx = new Tsrsubi1.Xormsga2();
etx.orderHeader.orderNo = "12321";
etx.clientTransactioId = "tran01";
etx.orderHeader.custId = "11111";
TSRWS.TSRTxns txns = new TSRWS.TSRTxns();
txns.ProcessTsrOrder(ref etx); // <<<< COMPILE ERROR HERE
txtMessage.Text = etx.messageText.ToString();
}
}
}

I am getting the following compile errors for some reason and don't know
why:

Error 1 The best overloaded method match for
'WebServiceTest.TSRWS.TSRTxns.ProcessTsrOrder(ref
WebServiceTest.TSRWS.Xormsga2)' has some invalid arguments C:\Documents and
Settings\bmattox\My Documents\Visual
Studio\Projects\TSRWS\WebServiceTest\Form1.cs 29 13 WebServiceTest
Error 2 Argument '1': cannot convert from 'ref
SoftwareAG.EntireX.NETWrapper.Generated.tsrsubi1.G roups.Tsrsubi1.Xormsga2'
to 'ref WebServiceTest.TSRWS.Xormsga2' C:\Documents and Settings\bmattox\My
Documents\Visual Studio\Projects\TSRWS\WebServiceTest\Form1.cs 29 38
WebServiceTest

Anyone have any suggestions?




 
Reply With Quote
 
 
 
 
Josh Twist
Guest
Posts: n/a
 
      02-03-2006
Because a web service leaves the appdomain (and process) boundary you
can't pass variables by reference (using the 'ref' keyword).

Therefore, when the proxy (client code) is generated it doesn't contain
the ref keyword and therefore there is no matching overload.

I have to say, I'm slightly surprised that the Web Service itself
doesn't throw an error when you try to access the help page or WSDL.

HTH

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
 
 
 
Ray Stevens
Guest
Posts: n/a
 
      02-03-2006
I think I am missing something basic. I tried a simple test passing
StringBuilder with no ref and get the same error:

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

private void btnTest_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
TSRWS.TSRTxns txns = new TSRWS.TSRTxns();
sb = txns.ProcessTsrOrder(sb);
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


"Josh Twist" <> wrote in message
news: oups.com...
> Because a web service leaves the appdomain (and process) boundary you
> can't pass variables by reference (using the 'ref' keyword).
>
> Therefore, when the proxy (client code) is generated it doesn't contain
> the ref keyword and therefore there is no matching overload.
>
> I have to say, I'm slightly surprised that the Web Service itself
> doesn't throw an error when you try to access the help page or WSDL.
>
> HTH
>
> Josh
> http://www.thejoyofcode.com/
>



 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      02-04-2006
Your example using StringBuilder is an interesting one - the
StringBuilder isn't designed to be serialized so the WSDL generator
creates it's own 'version' of sorts. You need to use that version
rather than the StringBuilder in System.Text in your web service
client. Weird I know, but try this it will work.

private void btnTest_Click(object sender, EventArgs e)
{
TSRWS.StringBuilder sb = new TSRWS.StringBuilder(); // it will
compile now, but this isn't a real stringbuilder so it won't work like
one.
TSRWS.TSRTxns txns = new TSRWS.TSRTxns();
sb = txns.ProcessTsrOrder(sb);
txtMessage.Text = sb.ToString();
}

There are a number of things going on here so bear with me whilst I try
to explain.

1. You can't send StringBuilders over web services. They must be used
within the same process they are created.

2. Getting to understand XmlSerialization is key to this whole process.
In order to send a class from one application to another (potentially
written in an entirely different language on a different platform -
thats the idea behind web services) the framework must change that
class/type into a format that can be sent in a (SOAP) message. To
achieve this in .NET web services, the framework uses the XmlSerializer
which serializes (converts) your class/types into XML sends it across
the wire. The other application then deserializes this XML back into
classes/types.

So - you can't pass things by reference. If you pass something by
reference your passing it by a pointer to memory - but how could the
other application (probably on a different computer) access the memory
of this application? It just doesn't make sense. And you can't pass an
*actual* System.Text.StringBuilder either, that contains heaps of
functionality, streams etc.

Try this example service instead as a working example

public class Employee
{
public string Name;
public int Age;
public string Email;
}

[WebMethod]
public Employee ReturnTheSameEmployee(Employee emp)
{
return emp;
}

Try that and let me know how you get on - in this case you'll be passed
back an exact copy of the employee object you pass in to the service.
Have a search on google for XmlSerializer and web services - there are
lot tutorials and introductions out there. If you need any more help -
just shout. Good luck!

 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      02-04-2006
This looks like a good place to start
http://www.builderau.com.au/architec...0282216,00.htm

You might want to jump to the section "Mapping XML to objects"

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      02-04-2006
Sorry - I posted the wrong link, I meant this one.

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

Sorry!

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting unable to cast error (when same object is referenced in client and web service) Rahul ASP .Net 5 03-01-2008 11:13 PM
Getting unable to cast error (when same object is referenced in client and web service) Rahul ASP .Net Web Services 5 03-01-2008 11:13 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Issues with assemblies referenced by a managed C++ web service Matthew Kane ASP .Net Web Services 1 05-16-2006 09:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57