[英]One entity shared across two web services?
I'm working on a project where I have 2 web services that need the same entity. 我正在开发一个项目,我有2个需要相同实体的Web服务。 The 2 web services are on the same server so on the back-end, they share the same classes.
2个Web服务位于同一台服务器上,因此在后端,它们共享相同的类。
On the front-end side, my code consumes both web services and sees the entities from both services as separate (in different namespaces) so I can't use the entity across both services. 在前端,我的代码使用两种 Web服务,并将两种服务中的实体视为独立的(在不同的名称空间中),因此我无法在两种服务中使用该实体。
Does anyone know of a way to allow this to work in .NET 2.0? 有谁知道允许它在.NET 2.0中工作的方法?
I've done this with my entity: 我用我的实体完成了这个:
[XmlType(TypeName = "Class1", Namespace = "myNamespace")]
public class Class1
{
public int field;
}
Hoping that my IDE would somehow "know" that the class is the same on both web services so that it wouldn't create separate entities for both classes, but no luck. 希望我的IDE以某种方式“知道”两个Web服务上的类是相同的,这样它就不会为这两个类创建单独的实体,但没有运气。
Is this possible to do with .NET 2.0 web services? 这可能与.NET 2.0 Web服务有关吗?
I think that you can not do that from inside VS but you can manually use the wsdl.exe
utility like this: 我认为你不能从VS内部做到这一点,但你可以像这样手动使用
wsdl.exe
实用程序:
wsdl.exe /sharetypes http://localhost/MyService1.asmx?wsdl http://localhost/MyService2.asmx?wsdl
Notice the /sharetypes
option which turns on the type sharing feature. 注意
/sharetypes
选项打开了类型共享功能。 This feature creates one code file with a single type definition for identical types shared between different services (the namespace, name, and wire signature must be identical). 此功能为不同服务之间共享的相同类型创建一个具有单一类型定义的代码文件(名称空间,名称和线路签名必须相同)。
More info: 更多信息:
I'm not sure about the implementation details with .NET 2.0, but I believe what you want to do is put the common classes in a seperate XSD file and refer to it from within your two WSDL's. 我不确定.NET 2.0的实现细节,但我相信你想要做的是将公共类放在一个单独的XSD文件中并从你的两个WSDL中引用它。 This way, the common types have the same namespace between the two services.
这样,公共类型在两个服务之间具有相同的命名空间。
Now, how you do this in .NET 2.0 I couldn't give you the specifics on... 现在,您如何在.NET 2.0中执行此操作我无法向您提供有关...的详细信息
Can you check the namespace of the entity? 你能检查实体的命名空间吗? Make sure it is the same in both the web services.
确保它们在两个Web服务中都相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.