Problem with WCF and multiple namespaces - sharing object types across multiple service references

后端 未结 4 828
闹比i
闹比i 2021-01-13 09:53

i have two web services. One with user functionality, one with admin functionality.

Both services effectively work with the same object types, for instance:

4条回答
  •  Happy的楠姐
    2021-01-13 10:17

    If you're controlling both ends of the communication, and both ends are .NET only, you could do this:

    • put all your contracts, including your data contracts, into a separate "Contracts" assembly
    • reference that assembly in both the server side implementation code, as well as the client side code

    If you do this, when adding the service references, WCF will find and use that shared assembly, and not create new types for the entitites. In your case, you'd only ever have one type Contracts.Customer or whatever you're dealing with.

    This works only if you control both ends of the wire and have .NET on both ends! But in that case, it's a great way to share contracts - especially data contracts - across both the server and any number of clients.

提交回复
热议问题