开发者

Class definition duplication in .NET client WCF proxy classes for Java web service

开发者 https://www.devze.com 2023-04-05 04:38 出处:网络
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 d

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


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.


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.

Class definition duplication in .NET client WCF proxy classes for Java web service

Now open the Reference.svcmap file and search for the MetadataSources node.

For example:

<MetadataSources>
    <MetadataSource Address="http://www.example.com/proxy_a/mex"
     Protocol="mex" SourceId="1" />
</MetadataSources>

Just add the URL for the second service (proxy_b) to this node. Don't forget to increment the SourceId attribute.

<MetadataSources>
  <MetadataSource Address="http://www.example.com/proxy_a/mex"
   Protocol="mex" SourceId="1" />
  <MetadataSource Address="http://www.example.com/proxy_b/mex"
   Protocol="mex" SourceId="2" />
</MetadataSources>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消