网络参考共享类
我用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用
wsdl.exe
时使用/sharetypes
选项:如果类完全匹配,并且在单个命令中为两个服务生成代码,则只应生成一次它们。两个服务将使用相同的类,因此不需要转换。
编辑:
如果 XML 命名空间不匹配(这种情况很常见),.NET 会认为它们是不同的类型,这是正确的。您要么必须修复 Web 服务,以使类型完全相同(推荐),要么在两个生成的类型之间进行转换。这将导致大量无聊的属性分配代码,因此您可能需要考虑使用类似 AutoMapper 为您处理转换。
wsdl.exe 应该生成 部分类,因此如果需要,您可以定义不同类型之间的隐式转换
:我自己通常不太喜欢隐式转换,但在这种情况下,它可能是有道理的。
Use the
/sharetypes
option when callingwsdl.exe
: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:
I'm not usually a big fan of implicit conversions myself, but in this case it might be warranted.
我解决了!
我按照 Thorarin 的提示使用了
wsdl.exe
选项sharetypes
。但仅使用此选项还不够。首先,您需要使用以下注释在 Java 服务器的 Webservice 类中设置正确的命名空间(使用 URI):其次,您需要相应地修改
createWebService.xml
中的设置:的网络服务需要像这样添加:就是这样!调用
wsdl.exe /parameters:createWebService.xml
即可完成。感谢您的帮助!
I solved it!
I followed the hint of Thorarin to use the
wsdl.exe
optionsharetypes
. 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:Second, you need to modify the settings in
createWebService.xml
accordingly: The namespace of the webservice needs to be added like this:That's it! Call
wsdl.exe /parameters:createWebService.xml
and you are done.Thanks for your help!