相同类型在不同的Web服务

相同类型在不同的Web服务

本文介绍了相同类型在不同的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的问题,因为这question.我有我消费与WCF,所有类型的共享多个Web服务。这些服务本身是用Java编写的,我没有对它们的访问。共享型具有相同的特征,但 svcutil.exe的使运行时,此错误:

I have a similar problem as this question. I have multiple web services that I am consuming with WCF, which all share types. The services themselves are written in Java and I do not have access to them. The shared types have the same signatures, but svcutil.exe gives this error when running:

Error: There was a validation error on a schema generated during export:
    Source:
    Line: 8 Column: 3
   Validation Error: The complexType 'http://MyServer.MyService:CommonType' has already been declared.

使用 CommonType 具有相同签名的两个Web服务被消耗。下面是我打电话 SvcUtil工具

With CommonType having the same signature in both web services being consumed. Here's how I'm calling svcutil:

svcutil.exe /o:GeneratedServices.cs /n:*,MyNamespace.Generated http://MyServer.MyService1?WSDL http://MyServer.MyService2?WSDL

我知道 Wsdl.exe用 / mergeTypes 标志,它适用于这些服务,但也有一些在 svcutil.exe的选项,我真的很喜欢用。我也有一个人证明它是可能的我,但是后端还使用了.NET和WCF和我已经成功与Java后端我使用。

I know that wsdl.exe has /mergeTypes flag, which works for these services, but there are some options on svcutil.exe that I'd really like to use. I did have someone demonstrate that it is possible to me, however the backend was also using .NET and WCF, and I've been unsuccessful with the Java backend I'm using.

推荐答案

首先 - 他们的完全一样吗?特别是,在SOAP命名空间必须匹配(除了一切)。如果他们不这样做,那么他们是不同的(不兼容)的类型;你将不得不使用2个不同的参考值(在不同的C#的命名空间,以避免冲突),并且这两种类型之间的数据转移。

First - are they exactly the same? In particular, the SOAP namespaces must match (in addition to everything else). If they don't, then they are different (incompatible) types; you will have to use 2 different references (in different C# namespaces to avoid conflicts), and shift data between the two types.

如果该类型的的相同,它仍然无法正常工作,那么你也许可以使用/ R开关SvcUtil工具从现有的组件消耗的类型。尝试使用一次,以获得第一类(只是从1网址) - 然后编译code到装配体。使用SvcUtil工具针对的第二的端点/ r标志识别您刚才生成的汇编。

If the types are the same and it still doesn't work, then you can perhaps use the /r switch with svcutil to consume the types from an existing assembly. Try using it once to get the first types (just from 1 of the urls) - then compile that code into an assembly. Use svcutil against the second endpoint with the /r flag identifying the assembly you generated moments ago.

请注意;相关主题是写一个部分类一个或更多的类型 - 例如,提供转换方法/对自己的类型的运算符。这可能使事情变得更简单。例如,你可以在不同的命名空间中写两个类似的类型之间的隐式(或显式)的静态转换操作符。

Note; a related topic is to write a partial class for one-or-more of the types - for example, to provide conversion methods/operators on the types themselves. This might make things simpler. For example, you could write an implicit (or explicit) static conversion operator between two similar types in different namespaces.

这篇关于相同类型在不同的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 20:02