1

I have 1 Site (MySite.com) / 1 Web Service (WebService.MySite.Com) and one Common Library (LibCommon)

The common Library Contains a Model e.g. UserModel = LibCommon.UserModel

The web service has a method 'Void CheckUser(LibCommon.UserModel model)'

However when I add the 'WebService' reference to 'MySite.com' the method changes so that it looks like 'Void CheckUser(WebService.MySite.Com.UserModel model)'

So I think fair enough I can just cast one object to the other as they are identical however .NET Says I cannot do this?

Is there a work around for this?

Cheers,

TheMonkeyMan
  • 8,622
  • 8
  • 27
  • 42

1 Answers1

1

Note this is for WCF, and not ASMX web services:

You can't directly cast the original data class to the proxied class generated by the WCF service reference wizard. However, you can reuse the original data class in the client:

  • Add the library reference containing the transfer objects (i.e. LibCommon) as a reference to both the Service (WebService) and the Client (Mysite.com). When adding the service reference on the client, choose the advanced tab and then select Reuse types in referenced assemblies. This will then reuse the common data transfer classes, instead of duplicating the types with proxies.

Note however that by eliminating the proxied data class, you are introducing direct coupling between client and server - you should do this only if you have control over both client and server w.r.t. version control issues etc (e.g. able to deploy new versions of both client and server simultaneously)

As an aside, it is also possible to eliminate the shared service interface as well, by moving the server side Service contract interface into a separate, common assembly and then using a technique such as this or this.

Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285