Java Web 服务的 .NET 客户端 WCF 代理类中的类定义重复
我正在为 Java Web 服务开发 .NET WCF 客户端。我可以从 Java Web 服务 WSDL 成功生成 .NET 代理类,并通过代理类调用该服务。一个问题是代理类中的类重复。假设我们有两个 java web 服务:java_a 和 java_b,都引用一个类 common_class。
现在,如果我在客户端为两个 Java Web 服务生成两个 .NET 代理类,例如:proxy_a 和 proxy_b。现在,在两个代理类中都有一个名为 common_class 的类,一个是 proxy_a.common_class,另一个是 proxy_b.common_class。我想为客户端的两个代理类编写一些辅助类,但很难处理 common_class。我必须编写许多重复代码来操作两个 common_class,我认为这不应该发生。应该可以手动修改代理类来提取 common_class,但由于我必须经常更新代理类,因此手动工作将非常痛苦。
所以我的问题是:在生成代理类时如何避免此类类定义重复?
此致, - 布鲁斯
I'm working on a .NET WCF client for a Java web service. I can generate the .NET proxy classes successfully from the Java web service WSDL and call the service via proxy class. One problem is class duplication in proxy classes. Say we have two java web service: java_a and java_b, both reference a class common_class.
Now if I generate two .NET proxy classes for the two Java web service at client, say: proxy_a and proxy_b. Now in both proxy classes there is a class called common_class, one is proxy_a.common_class and another is proxy_b.common_class. I want to write some helper class for the two proxy classes at client side but it's hard to deal with the common_class. I have to write many duplication code to manipulate the two common_class which should not happen in my opinion. It should be possible to manually modify the proxy classes to extract the common_class but since I will have to update the proxy classes very often it will be very painful to do the manual job.
So my question is: how to avoid such class definition duplication when generating proxy classes?
Best regards,
- Bruce
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以物理编辑一个类,并将其不作为序号文件添加到项目中,而是作为对两个项目中的文件的引用。不幸的是,您必须从此文件中删除名称空间声明,否则两个代理也无法一起工作。
You can edit physically one class and add it not as ordinal file to a project, but as reference to a file, in both projects. unfortunatelly, you have to strip namespace declaration from this file otherwize that 2 proxies whouldn't work together either.
您可以通过手动编辑 .SvcMap 文件来解决此问题。
为第一个 Web 服务 (proxy_a) 创建代理类。
然后转到解决方案资源管理器并确保选中“显示所有文件”选项。
现在打开 Reference.svcmap 文件并搜索 MetadataSources 节点。
例如:
只需将第二个服务 (proxy_b) 的 URL 添加到此节点即可。不要忘记增加 SourceId 属性。
右键单击服务引用并选择“更新服务引用”以重新生成客户端代码。现在,如果公司正确构建了服务并在需要时分配了命名空间,那么将为他们共享的公共类仅创建一种类型。
需要更多信息吗?我大约一个月前写了一篇关于这个问题的文章:
https://github.com/geersch/WcfSvcMap
希望有帮助。
You can solve this by manually editing the .SvcMap file.
Create the proxy classes for the first web service (proxy_a).
Then go to the Solution Explorer and make sure the "Show All Files" option is checked.
Now open the Reference.svcmap file and search for the MetadataSources node.
For example:
Just add the URL for the second service (proxy_b) to this node. Don't forget to increment the SourceId attribute.
Right-click on the service reference and select “Update Service Reference” in order to regenerate the client side code. Now if the company that built the services correctly and attributed namespaces where needed then only one type will be created for the common class which they share.
Need more information? I wrote an article about this issue a month ago or so:
https://github.com/geersch/WcfSvcMap
Hope it helps.