c# - How do you supply a type that's defined in a web service to another web service (share types)? -


i've got 2 wcf services. service contains definition of type myentity. service b contains service reference service , therefore can use type myentity. have method looks this:

protected void update (servicea.myentity entity) {     //do stuff } 

now want use method in service a, added service reference service b , tried:

protected updateserviceb(myentity entity) {     using(serviceb.serviceclient client =  new serviceb.serviceclient())     {         client.update(entity);     } } 

this didn't work , complained types not same, though service b using type defined in service a. how can solve this?

update

i avoided issue due time constraints , passed guid of myentity service service b instead. used existing method called 'getmyentity(guid entityid)' in service retrieve entity in service b:

protected void update (guid entityid) {     myentity entity = new myentity();              using (serviceaclient client = new serviceaclient())     {         entity = client.getmyentity(entityid);     }      //do stuff } 

sounds using service references way of visual studio's add service reference command. while adequate, can arguably become troublesome in medium large projects due to:

  1. service types re-defined in client rather using common library (as have discovered).

  2. when service contract changes, cause service updated not in client because of point 1. client proxies become stale overtime schema evolves. have refresh reference

my best suggestion not use add service reference , roll client proxies hand.

once performed have additional libraries:

  1. a.contracts.dll - here define service interfaces , data models service a
  2. b.contracts.dll - here define service interfaces , data models service b
  3. common.contracts.dll - if & b have common types, place them here. (canonical data models)
  4. a.service.dll - service implementation
  5. b.serivce.dll - service b implementation
  6. clientproxies.dll - roll-your-own client proxies services

you don't have implement of above now. required manual clientproxies.dll , can iterate rest later required.

more


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -