使用 WCF 两次公开同一个类
我有 2 个 WCF 服务公开相同的对象。假设第一个服务 (SerA) 公开一个类 (classA),第二个服务 (SerB) 添加填充的 classA 也公开此类(因为此类包含在参数中)现在,当我从 SerA 检索 classA 时,它与命名空间 SerA.classA 连接,当我使用第二个服务添加它时,它需要像 SerB.ClassA 这样的类。有没有办法指定两个类是相同的。我尝试更改 Reference.vb 中的命名空间,它可以工作,但是当更新服务引用时,这将是真正的问题。谁能帮我解决这个问题吗?谢谢
I have a 2 WCF services that are exposing the same object. Lets say the first service (SerA) exposes a class (classA) and the second service (SerB) which adds the filled classA also exposes this class (as this class is included in the parameters) Now when I retrieve the classA from SerA, it is concatenated with a namespace SerA.classA and when I add this using the second service, it requires a class like SerB.ClassA. Is there a way to specify that both classes are the same. I tried changing the namespace in reference.vb and it works but it would be real problem when the service reference is updated. Can anyone help me out in this? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
ClassA
(和其他数据协定)定义放入类库中,并从两个服务中引用它。这样,两者都应该使用相同的 DataContracts.ClassA 定义。将服务内容分离到单独的项目中始终是一个好主意:
这样,您也可以重用服务契约的某些部分以及可能的实现。
马克
You can put your
ClassA
(and other data contracts) definition into a class library and reference it from both services. That way, both should be using the sameDataContracts.ClassA
definition.It's always a good idea to separate your service stuff into separate projects:
This way, you can reuse certain parts of your service contracts and possibly implementations, too.
MArc
这个没有答案吧?
问题是服务引用生成自己的类定义。
例如,我在公共库中有一个类“car”,以及我正在使用的service1 wcf 服务来自 ClientProject 但当我添加对 service1 的引用时,您会
ClientProject.Service1_ref.Car
在 Reference.cs 中创建
现在我正在通过修改reference.cs以每次使用公共类来解决这个问题,确实不好。
编辑:
这家伙有答案,不要使用“添加服务引用”,否则很容易做到:http://devx.com/codemag/Article/39837/1763/page/5 – 怪物 X 0 秒前编辑
NO answer to this eh?
The problem is the service reference generates its own class definition..
eg, i have a class "car" in a common library, and service1 wcf service which i'm using from ClientProject but when i add a reference to service1, you get
ClientProject.Service1_ref.Car
created within Reference.cs
Right now i'm having to fix this by modifying the reference.cs to use the common classes each time, really not good.
edit:
This guy has the answer, don't use 'add service reference' its easy to do it elsewise: http://devx.com/codemag/Article/39837/1763/page/5 – Monsters X 0 secs ago edit