Reputation: 2828
I am adding a reference to a web service. In the web service I have a class named CustomerRecord
. I have a method named GetCustomerData()
which returns an array of CustomerRecord
class.
The project which will consume the webservice also has CustomerRecord
class.This is an exact representation of the one in Web Service.
Now when I use the web service, there are 2 CustomerRecord
classes.This leads to ambiguous reference error.
Upvotes: 1
Views: 1553
Reputation: 12721
If you use a web bservice, CustomerRecord
class must have the same namespace as the web service. To resolve the ambiguity right-click \ resolve and then write explicitly the needed namespace any reference to a CustomerRecord
object.
Since CustomerRecord
IS the same class, i suggest to delete the CustomerRecord
that is in the project that consumes web service, and use only the web service's one.
If you need to write particular code that is not needed by web service or is not serialized by SOAP remember that any class coming from a web method is PARTIAL, so you can write extra-code
public partial class CustomerRecord
{
....
Upvotes: 1
Reputation: 50672
In the line that gives the error, the compiler cannot decide which one of these two classes it should pick.
To solve this there are thee options:
Use a different namespace for both classes.
Delete one of the classes
Use an alias
The first option is only needed when both classes are in the same namespace and you want to keep them both.
The second option is useful when both classes are exactly the same. You could delete the one in the client or, when adding the service reference, select the re-use existing classes option so you keep the client version.
The last option works like this:
using ns1 = Some.CoolNamespace;
using ns2 = Another.CoolNaespace;
ns2.AClass x = new ...
Upvotes: 1
Reputation: 6440
The simple solution would be to rename one of them. But if you can't do that then you still have two options.
Remove the using from the top of the file that references both CustomerRecord classes, and simply refer to it using the full namespace.
My.Long.Namespace.CustomerRecord customer = new My.Long.Namespace.CustomerRecord();
Or, in that same file, use using to alias one of them, just for that file.
using WsCustomerRecord = My.Long.Namespace.CustomerRecord;
// ...
WsCustomerRecord customer = new WsCustomerRecord();
Upvotes: 1