简体   繁体   English

一个实体共享两个Web服务?

[英]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.

相关问题 Web服务和实体框架? - Web Services and Entity Framework? 实体框架在一个条件下跨两个表映射一个类 - Entity Framework mapping one class across two tables with a condition 在一个转发器中连接两个Nav Web服务数据 - join two Nav web services data in one repeater 如何在一个HttpServiceHost上托管两个或多个Web服务? - How can I host two or more web services on one HttpServiceHost? 通过两个Web服务(从WCF到WebApi)从WPF应用程序验证用户 - Authenticate user from WPF app across two web services (from WCF to WebApi) 枚举类型作为Web服务的常量? - Enumerated types as constants across web services? 实体框架跨两个数据库联接 - Entity Framework join across two databases VS2010中跨多个Web服务的通用DTO - Common DTOs across multiple web services in VS2010 如何使用 Entity Framework Core 定义一个实体 class 作为一个集合在多个实体之间共享? - How do I define an entity class to be shared as a collection across multiple entities using Entity Framework Core? 将ASP.net Web Forms C#中的两个下拉列表绑定到一个数据库实体中 - Binding two dropdownlist in ASP.net Web Forms C# into one database entity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM