网络参考共享类

发布于 2024-11-07 09:26:41 字数 663 浏览 5 评论 0原文

我用 Java 编写了一些 SOAP Web 服务,在 JBoss 5.1 上运行。 其中两个共享一个类,AddressTO。 Web 服务在我的 ApplycationServer 上正确部署,一切都很顺利,直到我尝试在我的 C# 客户端中使用类 addressTO 为止。客户端应用程序中有两种类型:addressTO 和addressTO1。这是一个问题,因为这会导致如下错误:

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

这意味着不可能隐式转换为类型。 AddressTo 类似于一个核心类,可供其他 Web 服务使用。

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

    wsdl.exe /parameters:CreateWebService.xml

xml 文件包含我的 web 服务的不同 .wsdl 文件的 url。

有人知道如何处理这个问题吗?

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

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.

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

    wsdl.exe /parameters:CreateWebService.xml

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

Does someone know how to handle this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人如初 2024-11-14 09:26:41

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

/共享类型
打开类型共享功能。此功能创建一个代码文件

之间共享的相同类型的单一类型定义
不同的
服务(命名空间、名称和电汇签名必须相同)。
使用 http:// URL 作为命令行引用服务
参数
或者为本地文件创建一个 discomap 文档。

如果类完全匹配,并且在单个命令中为两个服务生成代码,则只应生成一次它们。两个服务将使用相同的类,因此不需要转换。

编辑:

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

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

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

:我自己通常不太喜欢隐式转换,但在这种情况下,它可能是有道理的。

Use the /sharetypes option when calling wsdl.exe:

/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.

Edit:

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 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.

网名女生简单气质 2024-11-14 09:26:41

我解决了!

我按照 Thorarin 的提示使用了 wsdl.exe 选项 sharetypes。但仅使用此选项还不够。首先,您需要使用以下注释在 Java 服务器的 Webservice 类中设置正确的命名空间(使用 URI):

@WebService(targetNamespace="http://com/project/client/webservices/")
public class WebServiceImplementation implements WebService{
      // ... your @WebMethod-methods
}

其次,您需要相应地修改 createWebService.xml 中的设置:的网络服务需要像这样添加:

<wsdlParameters xmlns="http://microsoft.com/webReference/"> 
    <!-- Defaultsettings -->
    <language>CS</language> 
    <sharetypes>true</sharetypes>      
    <namespace>com.project.client.webservices</namespace> 

    <!-- output --> 
    <out>soap/WebServices.cs</out> 

    <appSettingUrlKey>BaseUrl</appSettingUrlKey>         
    <appSettingBaseUrl>http://localhost:8080</appSettingBaseUrl> 

    <!-- web service locations --> 
    <documents> 
        <document>http://localhost:8080/Core?wsdl</document>       
        <document>http://localhost:8080/WebService0?wsdl</document>    
        <document>http://localhost:8080/WebService1?wsdl</document> 
    </documents> 
</wsdlParameters>

就是这样!调用 wsdl.exe /parameters:createWebService.xml 即可完成。

感谢您的帮助!

I solved it!

I followed the hint of Thorarin to use the wsdl.exe option sharetypes. But to use this option is not enougth. First, you need to setup the correct namespace (using a URI) in the Webservice class in your java server with the following annotation:

@WebService(targetNamespace="http://com/project/client/webservices/")
public class WebServiceImplementation implements WebService{
      // ... your @WebMethod-methods
}

Second, you need to modify the settings in createWebService.xml accordingly: The namespace of the webservice needs to be added like this:

<wsdlParameters xmlns="http://microsoft.com/webReference/"> 
    <!-- Defaultsettings -->
    <language>CS</language> 
    <sharetypes>true</sharetypes>      
    <namespace>com.project.client.webservices</namespace> 

    <!-- output --> 
    <out>soap/WebServices.cs</out> 

    <appSettingUrlKey>BaseUrl</appSettingUrlKey>         
    <appSettingBaseUrl>http://localhost:8080</appSettingBaseUrl> 

    <!-- web service locations --> 
    <documents> 
        <document>http://localhost:8080/Core?wsdl</document>       
        <document>http://localhost:8080/WebService0?wsdl</document>    
        <document>http://localhost:8080/WebService1?wsdl</document> 
    </documents> 
</wsdlParameters>

That's it! Call wsdl.exe /parameters:createWebService.xml and you are done.

Thanks for your help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文