views:

287

answers:

3

I'm working on a project where I have 2 web services that need the same entity. The 2 web services are on the same server so on the back-end, they share the same classes.

On the front-end side, my code consumes both web services and sees the entities from both services as separate (in different namespaces) so I can't use the entity across both services.

Does anyone know of a way to allow this to work in .NET 2.0?

I've done this with my entity:

[XmlType(TypeName = "Class1", Namespace = "myNamespace")]
public class Class1
{
    public int field;
}

Hoping that my IDE would somehow "know" that the class is the same on both web services so that it wouldn't create separate entities for both classes, but no luck.

Is this possible to do with .NET 2.0 web services?

+1  A: 

I'm not sure about the implementation details with .NET 2.0, but I believe what you want to do is put the common classes in a seperate XSD file and refer to it from within your two WSDL's. This way, the common types have the same namespace between the two services.

Now, how you do this in .NET 2.0 I couldn't give you the specifics on...

matt b
A: 

Can you check the namespace of the entity? Make sure it is the same in both the web services.

Syed Sajid Nizami
+4  A: 

I think that you can not do that from inside VS but you can manually use the wsdl.exe utility like this:

wsdl.exe /sharetypes http://localhost/MyService1.asmx?wsdl http://localhost/MyService2.asmx?wsdl

Notice the /sharetypes option which turns on the type sharing feature. This feature creates one code file with a single type definition for identical types shared between different services (the namespace, name, and wire signature must be identical).

More info:

Panos