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

Discussion in 'ASP .Net Web Services' started by Ray Stevens, Feb 2, 2006.

  1. Ray Stevens

    Ray Stevens Guest

    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.Groups
    {
    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.Groups;

    [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.Groups;

    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.Groups.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?
    Ray Stevens, Feb 2, 2006
    #1
    1. Advertising

  2. Ray Stevens

    Josh Twist Guest

    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/
    Josh Twist, Feb 3, 2006
    #2
    1. Advertising

  3. Ray Stevens

    Ray Stevens Guest

    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(WebServiceTest.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:...
    > 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/
    >
    Ray Stevens, Feb 3, 2006
    #3
  4. Ray Stevens

    Josh Twist Guest

    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!
    Josh Twist, Feb 4, 2006
    #4
  5. Ray Stevens

    Josh Twist Guest

    Josh Twist, Feb 4, 2006
    #5
  6. Ray Stevens

    Josh Twist Guest

    Josh Twist, Feb 4, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,744
    Smokey Grindel
    Dec 2, 2006
  2. Nagaraj
    Replies:
    1
    Views:
    836
    Lionel B
    Mar 1, 2007
  3. Rahul
    Replies:
    5
    Views:
    398
    John Saunders [MVP]
    Mar 1, 2008
  4. Matthew Kane

    Issues with assemblies referenced by a managed C++ web service

    Matthew Kane, May 15, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    159
    Steven Cheng[MSFT]
    May 16, 2006
  5. Rahul
    Replies:
    5
    Views:
    222
    John Saunders [MVP]
    Mar 1, 2008
Loading...

Share This Page