473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

namespace's conflict

Hi,

I have 3 projects:

1. Common

2. Desktop

3. WebServices

The Common is used in Desktop and WebServices project.

In Common I have the class Order.

I get the value for Order class from WebServices like this:

Order order = null;

order = localhost.GetOrder();

If I use different namespace in Common and Desktop I'll get this error,
which is correct.

Cannot convert source type Order to target name Common.Order.

But if I use the same namespace for both Common and Desktop project the
application work perfect. Is that OK, or can I have the problems in the
future? Should I convert the Order class from localhost to Common (using
IXmlSerializable, for instance)?

Thanks a lot

Ruslan

Nov 23 '05 #1
4 4009
Hello Ruslan,
I believe you are trying to share types... refer the post titled "two
references to the same class in WebService client problem"

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Hi,

I have 3 projects:

1. Common

2. Desktop

3. WebServices

The Common is used in Desktop and WebServices project.

In Common I have the class Order.

I get the value for Order class from WebServices like this:

Order order = null;

order = localhost.GetOrder();

If I use different namespace in Common and Desktop I'll get this
error, which is correct.

Cannot convert source type Order to target name Common.Order.

But if I use the same namespace for both Common and Desktop project
the application work perfect. Is that OK, or can I have the problems
in the future? Should I convert the Order class from localhost to
Common (using IXmlSerializable, for instance)?

Thanks a lot

Ruslan

Nov 23 '05 #2
Hi Dilip,

Maybe, I can't find this post, but it sounds similar to my problem. Could
you tell me the link?

Thank you,
Ruslan
"Dilip Krishnan" <dk*******@NOSPAM.geniant.com> wrote in message
news:21**********************@msnews.microsoft.com ...
Hello Ruslan,
I believe you are trying to share types... refer the post titled "two
references to the same class in WebService client problem"

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Hi,

I have 3 projects:

1. Common

2. Desktop

3. WebServices

The Common is used in Desktop and WebServices project.

In Common I have the class Order.

I get the value for Order class from WebServices like this:

Order order = null;

order = localhost.GetOrder();

If I use different namespace in Common and Desktop I'll get this
error, which is correct.

Cannot convert source type Order to target name Common.Order.

But if I use the same namespace for both Common and Desktop project
the application work perfect. Is that OK, or can I have the problems
in the future? Should I convert the Order class from localhost to
Common (using IXmlSerializable, for instance)?

Thanks a lot

Ruslan


Nov 23 '05 #3
Console app
webservice Order class (with namespace)
Common.Order class
Code follows
--------------------------------
Console test harness
--------------------------------
using System;
using Common; //for Common.Order class
using OrdersWebservice; //for OrdersWebservice.Order class

namespace Test
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class WebServiceConsumer
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//Instantiate Oder class from the OrdersWebservice namespace
OrdersWebservice.Order order0 = new OrdersWebservice.Order();

//Instantiate Oder class from the Common namespace
Common.Order order1 = new Common.Order();

//The commented code line below will have a compile error
//because the compiler cannot determine which Order class to use
//Order order2 = new OrdersWebservice.Order();
Console.WriteLine("OrdersWebservice.Order() " + order0.GetOrder(0));
Console.WriteLine("Common.Order() " + order1.GetOrder(0));

//Pause to keep console active
WaitApp();
}

public static void WaitApp()
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press <enter/return> key to exit this application");
Console.ReadLine();
}
}//~class
}//~namespace

--------------------------------------------------------------
Webservice Order class in OrdersWebservice namespace
--------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace OrdersWebservice
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Order : System.Web.Services.WebService
{
public Order()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the project
// To test this web service, press F5

[WebMethod]
public string GetOrder(int productId)
{
//productId is not used because just example code
//test data only, I would query a database if a real webservice
return "0-596-00006-5|O'Reilly|Physics for Game Developers";
}

}//~class
}//~namespace

---------------------------------------
Order class in Common namespace
---------------------------------------
using System;

namespace Common
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Order
{
public Order()
{

}

public string GetOrder(int productId)
{
//productId is not used because just example code
//test data only, I would query a database if a business object
return "1-59059-344-8|Apress |Expert C# Business Objects";
}
}//~class
}//~namespace
"Ruslan" <ru*********@hotmail.com> wrote in message
news:eh**************@TK2MSFTNGP15.phx.gbl...
Hi,

I have 3 projects:

1. Common

2. Desktop

3. WebServices

The Common is used in Desktop and WebServices project.

In Common I have the class Order.

I get the value for Order class from WebServices like this:

Order order = null;

order = localhost.GetOrder();

If I use different namespace in Common and Desktop I'll get this error,
which is correct.

Cannot convert source type Order to target name Common.Order.

But if I use the same namespace for both Common and Desktop project the
application work perfect. Is that OK, or can I have the problems in the
future? Should I convert the Order class from localhost to Common (using
IXmlSerializable, for instance)?

Thanks a lot

Ruslan

Nov 23 '05 #4
Console app
webservice Order class (with namespace)
Common.Order class
Code follows
--------------------------------
Console test harness
--------------------------------
using System;
using Common; //for Common.Order class
using OrdersWebservice; //for OrdersWebservice.Order class

namespace Test
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class WebServiceConsumer
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//Instantiate Oder class from the OrdersWebservice namespace
OrdersWebservice.Order order0 = new OrdersWebservice.Order();

//Instantiate Oder class from the Common namespace
Common.Order order1 = new Common.Order();

//The commented code line below will have a compile error
//because the compiler cannot determine which Order class to use
//Order order2 = new OrdersWebservice.Order();
Console.WriteLine("OrdersWebservice.Order() " + order0.GetOrder(0));
Console.WriteLine("Common.Order() " + order1.GetOrder(0));

//Pause to keep console active
WaitApp();
}

public static void WaitApp()
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press <enter/return> key to exit this application");
Console.ReadLine();
}
}//~class
}//~namespace

--------------------------------------------------------------
Webservice Order class in OrdersWebservice namespace
--------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace OrdersWebservice
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Order : System.Web.Services.WebService
{
public Order()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the project
// To test this web service, press F5

[WebMethod]
public string GetOrder(int productId)
{
//productId is not used because just example code
//test data only, I would query a database if a real webservice
return "0-596-00006-5|O'Reilly|Physics for Game Developers";
}

}//~class
}//~namespace

---------------------------------------
Order class in Common namespace
---------------------------------------
using System;

namespace Common
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Order
{
public Order()
{

}

public string GetOrder(int productId)
{
//productId is not used because just example code
//test data only, I would query a database if a business object
return "1-59059-344-8|Apress |Expert C# Business Objects";
}
}//~class
}//~namespace
"Ruslan" <ru*********@hotmail.com> wrote in message
news:eh**************@TK2MSFTNGP15.phx.gbl...
Hi,

I have 3 projects:

1. Common

2. Desktop

3. WebServices

The Common is used in Desktop and WebServices project.

In Common I have the class Order.

I get the value for Order class from WebServices like this:

Order order = null;

order = localhost.GetOrder();

If I use different namespace in Common and Desktop I'll get this error,
which is correct.

Cannot convert source type Order to target name Common.Order.

But if I use the same namespace for both Common and Desktop project the
application work perfect. Is that OK, or can I have the problems in the
future? Should I convert the Order class from localhost to Common (using
IXmlSerializable, for instance)?

Thanks a lot

Ruslan


Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: James Bradley | last post by:
Hi Folks, I am coming up to speed with C# and I have run into an interesting issue. I have an old VB COM library that I need to access with a ProgId == 'xyz' I also have a C# class that is...
0
by: linkan56 | last post by:
I'm using stubs to unit test an existing system. I use the stubs not only as an empty shell for the real implementations, but also to control and check the behaviour of units. I have included test...
9
by: Brett Romero | last post by:
I have two projects in one solution - a library and executable. Each have a namespace such as: ROOT.myapp.Functional ROOT.myapp.UI However, each cannot reference the other. myapp.UI is...
12
by: bgeneto | last post by:
I know that it's a very basic question, but I can't figure out or find an answer to why do we have to specify a namespace, like this #include<string> using namespace std; when using the...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
by: Frederick Gotham | last post by:
Back in the day, if you wanted a function to be self-contained within a translation unit, you defined the function as "static". If there were an external linkage function by the same name...
1
by: vsgdp | last post by:
I just want to clarify: Say I have a helper class that is only used in one translation file (e.g., a predicate class). I don't want the name of this class to conflict with other class names in...
3
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer...
4
by: Andrew | last post by:
I am having an interesting namespace conflict. When we use a third party lib we create a company assembly for any descending classes to go in. I have simplified the problem into the example...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.