Web参考共享类 [英] Webreferences sharing classes

查看:93
本文介绍了Web参考共享类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Java编写了一些SOAP Webservices,它们在JBoss 5.1上运行. 他们两个共享一个类,AddressTO. Web服务在我的ApplycationServer上正确部署,并且一切运行良好,直到我尝试在C#客户端中使用类addressTO为止.客户端应用程序中有两种类型,即addressTO和addressTO1.这是一个问题,因为这会导致以下错误:

I wrote a few SOAP Webservices in Java, running on a JBoss 5.1. Two of them share a class, AddressTO. The Webservices are deploying correctly on my ApplycationServer and all went well until I try to use the class addressTO in my C#-client. There are two types in the client application, addressTO and addressTO1. This is a problem because this causes errors like:

    Fehler  1   Eine implizite Konvertierung vom Typ 
    "acsysteme.i4workspace.client.webservices.addressTO1[]" in 
    "acsysteme.i4workspace.client.webservices.addressTO[]" ist nicht möglich.   
    [...]

这意味着不可能将隐式转换为类型. AddressTo类似于核心类,可以被其他Web服务使用.

This means that it is impossible to cast the to types implicitly. AddressTo is something like a core class which can be used by other webservices.

C#客户端的Web引用是通过命令创建的

The webreferences for the C#-client are created by the command

    wsdl.exe /parameters:CreateWebService.xml

该xml文件包含我的Web服务的不同.wsdl文件的URL.

The xml-file contains the urls to the differend .wsdl-files of my webservices.

有人知道如何解决这个问题吗?

Does someone know how to handle this problem?

推荐答案

在调用wsdl.exe时使用/sharetypes选项:

/共享类型 打开类型共享功能.此功能创建一个代码文件 和 相同类型之间共享的单个类型定义 不同的 服务(名称空间,名称和线路签名必须相同). 使用http://URL作为命令行引用服务 参数 或为本地文件创建分解文档.

/sharetypes Turns on type sharing feature. This feature creates one code file with a single type definition for identical types shared between different services (namespace, name and wire signature must be identical). Reference the services with http:// URLs as command-line parameters or create a discomap document for local files.

如果类完全匹配,则如果您在单个命令中为两个服务生成代码,则它们仅应生成一次.两种服务都将使用相同的类,因此无需进行转换.

If the classes match exactly, they should only be generated once if you generate code for both services in a single command. Both services will be using the same class, so no conversion will be necessary.

如果XML名称空间不匹配(这是常见的情况),. NET将认为它们是不同的类型,这是正确的.您将必须修复Web服务以使类型完全相同(推荐),或者在两种生成的类型之间进行转换.这将导致大量无聊的属性分配代码,因此您可能要考虑使用类似 AutoMapper 为您处理转换.

If the XML namespaces do not match (which is a common occurrence), .NET will consider them to be different types, and rightly so. You will either have to fix the web services so the types are exactly the same (recommended), or do conversion between the two generated types. This will result in a lot of boring property assignment code, so you might want to consider using something like AutoMapper to handle the conversion for you.

wsdl.exe应该生成部分类,因此,如果需要,您可以在不同之间定义隐式转换类型:

wsdl.exe should generate partial classes, so if you want, you can define implicit conversions between the different types:

public static implicit operator addressTO1(addressTO source)
{
    addressTO1 result = new addressTO1();
    // Assign properties, etc.
    return result;
}

我通常自己并不喜欢隐式转换,但是在这种情况下,我可以保证这样做.

I'm not usually a big fan of implicit conversions myself, but in this case it might be warranted.

这篇关于Web参考共享类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆