none
Generating two WCF services that use the same data contract

    Question

  • Hi, I have two WCF Services than use the same DataContract. For generating ServiceClient I use svcutil tool.  Every generated file contains the definition for my DataContract. In my case I have a conflict at compile time because two classes have the same name. Is the svcutil can do the “merge” between data contracts by not defining repeated elements? How can I resolve this problem?

    Monday, November 20, 2006 1:39 PM

Answers

  • The best I think you can do is this:

    1. Generate proxies using the /namespace option to map schema namespaces to CLR namespaces so that the two sets of imported data contracts look like the same type at the client. That way, after you manually delete one copy of the redundant types, both service proxies will work properly and see the types as the same from a CLR perspective (they always look the same when serialized, since the XML namespace is the same).
    2. You'll have to manually delete the redundant types.
    3. Java clients use their own proxy generation tool. Maybe it is better, smarter, faster and will not duplicate? Each proxy generation tool is different.

     

    Tuesday, November 21, 2006 5:25 PM
    Moderator

All replies

  • If you own both sides and want to share a class library with the data contract types in it for both services and clients, you can reference the assembly when you generate the proxy:

    svcutil /config:app.config /o:serviceproxy.cs /r:SharedTypes.dll http://localhost:8000

    If you want to use svcutil and create a service proxy for more than one service, I believe you can use svcutil to generate proxy for more than one WSDL at a time, by supplying multple endpoints at the end of the command.

    svcutil /config:app.config /o:serviceproxy.cs http://localhost:8000/ServiceA http://localhost:8000/ServiceB

    Monday, November 20, 2006 9:04 PM
    Moderator
  • Hi, in my case the command

    svcutil /config:app.config /o:serviceproxy.cs http://localhost:8000/ServiceA http://localhost:8000/ServiceB

    does not work, because the svcutil don't "understand" than two services can use the same data contract.

    The command

    svcutil /config:app.config /o:serviceproxy.cs /r:SharedTypes.dll http://localhost:8000

    does not suit because

    1. I have no the assembly with only DataContract classes

    2. "SharedTypes.dll" is a .net compiled. I need to use the java client too, end tool must genarate "Data Contract".

     

    Now i need to delete all duplicated data contracts. Have you other

    possibilities?

     

     

    Tuesday, November 21, 2006 1:22 PM
  • The best I think you can do is this:

    1. Generate proxies using the /namespace option to map schema namespaces to CLR namespaces so that the two sets of imported data contracts look like the same type at the client. That way, after you manually delete one copy of the redundant types, both service proxies will work properly and see the types as the same from a CLR perspective (they always look the same when serialized, since the XML namespace is the same).
    2. You'll have to manually delete the redundant types.
    3. Java clients use their own proxy generation tool. Maybe it is better, smarter, faster and will not duplicate? Each proxy generation tool is different.

     

    Tuesday, November 21, 2006 5:25 PM
    Moderator
  • Thank you,

    I already use the  /namespace option and every time i need to delete all redundant types definition. For now there is no possibility to generate client correctly in my case.

    Thursday, November 23, 2006 10:44 AM
  • In our project we have around 30 web services and we were trying to generate a single serviceproxy class, it took above an hr to generate the service proxy, this was creating issues for us. We decided to generate multple Serivce Proxies and used the SVCUTIL /r switch to avoid type duplicates, this helped us in getting the time down to 8 minutes

    This is the approach we followed
    We generated the First Service proxy as ServiceProxy1.cs
    svcutil /serializer:DataContractSerializer /serializable /out:ServiceProxy1.cs https://localhost/myservices/service1.svc https://localhost/myservices/service2.svc https://localhost/myservices/service3.svc

    compiled the serviceproxy1 into a dll
    csc.exe /t:library /out:ServiceProxy.dll ServiceProxy1.cs

    Generated the Second Service Proxy using the generated dll as reference to avoid type duplicates
    svcutil /serializer:DataContractSerializer /serializable /out:ServiceProxy2.cs /r:ServiceProxy.dll https://localhost/myservices/service4.svc https://localhost/myservices/service5.svc  https://localhost/myservices/service6.svc

    Compiled ServiceProxy1.cs and ServiceProxy2.cs into a dll
    csc.exe /t:library /out:ServiceProxy.dll ServiceProxy1.cs ServiceProxy2.cs

    Generated the Third Service Proxy using the generated dll as reference to avoid type duplicates
    svcutil /serializer:DataContractSerializer /serializable /out:ServiceProxy3.cs /r:ServiceProxy.dll https://localhost/myservices/service7.svc https://localhost/myservices/service8.svc https://localhost/myservices/service9.svc

    Now i can use my ServiceProxy1.cs, ServiceProxy2.cs, and ServiceProxy3.cs files in my project without any compilation issues

    Thursday, June 24, 2010 10:18 PM