Ambiguous reference between X and Y problem

Discussion in 'ASP .Net Web Services' started by Simon, Mar 14, 2009.

  1. Simon

    Simon Guest

    I am referencing the same class library in Web service and in application
    and I get the ambiguous reference error.

    How can I slove this problem?

    Thank you

    Simon
    Simon, Mar 14, 2009
    #1
    1. Advertising

  2. Simon

    Simon Guest

    Ambiguous reference between X and Y problem - part 2

    Follow up on this question with some code. I get errors:

    Error 1 'TestName' is an ambiguous reference between 'TestClass.TestName'
    and 'TestApp.WebService.TestName' C:\NET\TestWeb\TestApp\Form1.cs 23 13
    TestApp

    This is the problem, because I would like to use the same class in both web
    service and application. How can I avoid this?

    Thank you for your help

    Simon



    *** Appliation that references web service and class library:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using TestClass;
    using TestApp.WebService;

    namespace TestApp
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    TestName name;
    ServiceTest serv;

    name.Name = this.textBox1.Text;
    serv = new ServiceTest();
    serv.Test1(name);
    this.textBox2.Text = name.Name;
    }
    }
    }

    *** Class library:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace TestClass
    {
    public class TestName
    {
    public TestName()
    {
    Name = "";
    }

    public String Name
    {
    get;
    set;
    }
    }
    }

    *** And web service that also references class library:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using TestClass;

    namespace TestService
    {
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET
    AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class ServiceTest : System.Web.Services.WebService
    {
    [WebMethod]
    public void Test1(TestName test)
    {
    test.Name += " CHECKED";
    }
    [WebMethod]
    public void Test2(TestName test)
    {
    test.Name += " CHECKED";
    }
    }
    }
    Simon, Mar 16, 2009
    #2
    1. Advertising

  3. Simon

    Pipo Guest

    Re: Ambiguous reference between X and Y problem - part 2

    Rename one of the functions...
    OR
    Do in the usings
    using TestApp
    and prefix the call (WebService.ServiceTest serv;)
    OR
    using x = TestApp.WebService;
    and then x.ServiceTest serv;


    "Simon" <> wrote in message
    news:...
    > Follow up on this question with some code. I get errors:
    >
    > Error 1 'TestName' is an ambiguous reference between 'TestClass.TestName'
    > and 'TestApp.WebService.TestName' C:\NET\TestWeb\TestApp\Form1.cs 23 13
    > TestApp
    >
    > This is the problem, because I would like to use the same class in both
    > web service and application. How can I avoid this?
    >
    > Thank you for your help
    >
    > Simon
    >
    >
    >
    > *** Appliation that references web service and class library:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.ComponentModel;
    > using System.Data;
    > using System.Drawing;
    > using System.Linq;
    > using System.Text;
    > using System.Windows.Forms;
    > using TestClass;
    > using TestApp.WebService;
    >
    > namespace TestApp
    > {
    > public partial class Form1 : Form
    > {
    > public Form1()
    > {
    > InitializeComponent();
    > }
    >
    > private void button1_Click(object sender, EventArgs e)
    > {
    > TestName name;
    > ServiceTest serv;
    >
    > name.Name = this.textBox1.Text;
    > serv = new ServiceTest();
    > serv.Test1(name);
    > this.textBox2.Text = name.Name;
    > }
    > }
    > }
    >
    > *** Class library:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.Linq;
    > using System.Text;
    >
    > namespace TestClass
    > {
    > public class TestName
    > {
    > public TestName()
    > {
    > Name = "";
    > }
    >
    > public String Name
    > {
    > get;
    > set;
    > }
    > }
    > }
    >
    > *** And web service that also references class library:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.Linq;
    > using System.Web;
    > using System.Web.Services;
    > using TestClass;
    >
    > namespace TestService
    > {
    > /// <summary>
    > /// Summary description for Service1
    > /// </summary>
    > [WebService(Namespace = "http://tempuri.org/")]
    > [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    > [System.ComponentModel.ToolboxItem(false)]
    > // To allow this Web Service to be called from script, using ASP.NET
    > AJAX, uncomment the following line.
    > // [System.Web.Script.Services.ScriptService]
    > public class ServiceTest : System.Web.Services.WebService
    > {
    > [WebMethod]
    > public void Test1(TestName test)
    > {
    > test.Name += " CHECKED";
    > }
    > [WebMethod]
    > public void Test2(TestName test)
    > {
    > test.Name += " CHECKED";
    > }
    > }
    > }
    Pipo, Mar 18, 2009
    #3
    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. Replies:
    2
    Views:
    951
  2. zoe
    Replies:
    14
    Views:
    657
    John C. Bollinger
    Dec 18, 2003
  3. LaCo
    Replies:
    5
    Views:
    1,614
    Roedy Green
    May 13, 2004
  4. Replies:
    3
    Views:
    816
    Martin Thompson
    Jan 10, 2007
  5. Oliver Wong
    Replies:
    15
    Views:
    1,467
    Twisted
    Jul 21, 2007
Loading...

Share This Page