Java工具创建的WSDL文件的WCF序列化问题 [英] WCF Serialization problems with WSDL file created by Java tools

查看:76
本文介绍了Java工具创建的WSDL文件的WCF序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队的任务是获得几个内部开发的.NET客户端应用程序,以连接到一些新的Java Web服务. Java Web服务是第三方提供的,由供应商提供的WSDL文件,我们的团队具有有限的修改/控制能力……这意味着我们可能有权要求我们的供应商对WSDL进行一些细微调整,但可能会进行重大更改不可行或难以请求.

也就是说,我们正在尝试利用WCF/.NET 4.0生成客户端所需的.NET代理类文件.代理客户端类文件生成过程的执行没有问题.

问题是当我们尝试在客户端应用程序中使用代理类文件时.我已经通过Web跟踪工具Fiddler验证了原始SOAP消息请求无法通过电线发送到服务器.

当我尝试调用有问题的Web服务方法时收到的特定.NET异常消息看起来像这样:

System.InvalidOperationException未处理 Message = XmlSerializer属性System.Xml.Serialization.XmlAttributeAttribute在baseLanguage中无效. IsWrapped为true时,仅支持XmlElement,XmlArray,XmlArrayItem,XmlAnyAttribute和XmlAnyElement属性. Source = System.ServiceModel

当我检查.NET自动生成的代理类文件Reference.cs时,我注意到我的Web服务方法的请求和响应消息看起来像这样:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="QueryPBOT_MXWO_OS", WrapperNamespace="http://www.ibm.com/maximo", IsWrapped=true)]
public partial class QueryPBOT_MXWO_OSRequest {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=0)]
    public ConsoleApplication7.wsMaximo.PBOT_MXWO_OSQueryType PBOT_MXWO_OSQuery;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=1)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string baseLanguage;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=2)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string transLanguage;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=3)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string messageID;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=4)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string maximoVersion;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=5)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    [System.ComponentModel.DefaultValueAttribute(false)]
    public bool uniqueResult;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=6)]
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")]
    public string maxItems;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=7)]
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="integer")]
    [System.ComponentModel.DefaultValueAttribute("0")]
    public string rsStart;

    public QueryPBOT_MXWO_OSRequest() {
    }

    public QueryPBOT_MXWO_OSRequest(ConsoleApplication7.wsMaximo.PBOT_MXWO_OSQueryType PBOT_MXWO_OSQuery, string baseLanguage, string transLanguage, string messageID, string maximoVersion, bool uniqueResult, string maxItems, string rsStart) {
        this.PBOT_MXWO_OSQuery = PBOT_MXWO_OSQuery;
        this.baseLanguage = baseLanguage;
        this.transLanguage = transLanguage;
        this.messageID = messageID;
        this.maximoVersion = maximoVersion;
        this.uniqueResult = uniqueResult;
        this.maxItems = maxItems;
        this.rsStart = rsStart;
    }
}

我知道阅读这篇文章的人会希望看到我们试图使用的实际WSDL文件,但是它很大,而且我担心它的庞大大小将使查明错误非常困难. /p>

我希望自动生成的客户端代理文件和.NET异常将帮助某人识别此WCF序列化问题.

我们已经从我们的Java供应商处确认,他们生成的WSDL样式是基于文档的.在Internet上进行了一些研究之后,默认情况下似乎是WCF.转换带有文档文字的WSDL文件,这至少可以部分解释为什么我们会看到WSDL文件出现WCF序列化的问题.

通过反复试验,我发现代理类文件中的以下属性修饰符是导致序列化问题的元凶:

[System.Xml.Serialization.XmlAttributeAttribute()]

如果我在代理类文件中注释掉了该属性的所有实例,然后重新运行我的客户端应用程序,则SOAP消息将成功通过网络发送,并且我将从服务器返回有效的Web服务响应.

此修复总比没有好,但是我非常希望该解决方案不需要我自己或团队中的任何人来不断调整这些.NET自动生成的代理类文件.

我想知道是否可以通过各种WCF工具或通过修改WSDL文件来执行某些操作,以防止将[System.Xml.Serialization.XmlAttributeAttribute()]应用于我的请求并响应对象的属性?

或者至少是对WHY的简要描述,我们在Java WSDL文件中看到了.NET中的这种序列化行为?

先谢谢了, 约翰

解决方案

svcutil.exe 实用程序与/wrapped 选项一起使用,以生成代理类.

这将创建与通过Visual Studio通过Ladislav Mrnka在此处描述的方式创建的类稍有不同的类.在客户端使用时,生成的代理应该不受XmlAttribute问题的影响.

示例:

svcutil /t:code wsdl.xml /out:wsdl.cs /serializer:XmlSerializer /wrapped

My team is tasked with getting several in-house developed .NET client applications to connect to some new Java web services. The Java web service is a third party, vendor supplied WSDL file that our team has a limited ability to modify/control...meaning we probably have the power to request our vendor to make slight tweaks to the WSDL, but major changes would probably be either unfeasible or difficult to request.

That said, we are attempting to utilize WCF/.NET 4.0 to generate the .NET proxy class files we need on the client side. The proxy client class file generation process executes without issues.

The problem is when we attempt to use the proxy class file in a client app. I have verified through the web trace tool, Fiddler, that the raw SOAP message request fails to get sent across the wire to the server.

The specific .NET exception message I get when attempting to call the web service method in question, looks like this:

System.InvalidOperationException was unhandled Message=XmlSerializer attribute System.Xml.Serialization.XmlAttributeAttribute is not valid in baseLanguage. Only XmlElement, XmlArray, XmlArrayItem, XmlAnyAttribute and XmlAnyElement attributes are supported when IsWrapped is true. Source=System.ServiceModel

When I examine the .NET autogenerated proxy class file, Reference.cs, I noticed that the request and response messages for my web service method looks something like this:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="QueryPBOT_MXWO_OS", WrapperNamespace="http://www.ibm.com/maximo", IsWrapped=true)]
public partial class QueryPBOT_MXWO_OSRequest {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=0)]
    public ConsoleApplication7.wsMaximo.PBOT_MXWO_OSQueryType PBOT_MXWO_OSQuery;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=1)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string baseLanguage;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=2)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string transLanguage;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=3)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string messageID;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=4)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string maximoVersion;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=5)]
    [System.Xml.Serialization.XmlAttributeAttribute()]
    [System.ComponentModel.DefaultValueAttribute(false)]
    public bool uniqueResult;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=6)]
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")]
    public string maxItems;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.ibm.com/maximo", Order=7)]
    [System.Xml.Serialization.XmlAttributeAttribute(DataType="integer")]
    [System.ComponentModel.DefaultValueAttribute("0")]
    public string rsStart;

    public QueryPBOT_MXWO_OSRequest() {
    }

    public QueryPBOT_MXWO_OSRequest(ConsoleApplication7.wsMaximo.PBOT_MXWO_OSQueryType PBOT_MXWO_OSQuery, string baseLanguage, string transLanguage, string messageID, string maximoVersion, bool uniqueResult, string maxItems, string rsStart) {
        this.PBOT_MXWO_OSQuery = PBOT_MXWO_OSQuery;
        this.baseLanguage = baseLanguage;
        this.transLanguage = transLanguage;
        this.messageID = messageID;
        this.maximoVersion = maximoVersion;
        this.uniqueResult = uniqueResult;
        this.maxItems = maxItems;
        this.rsStart = rsStart;
    }
}

I know that people reading this post will want to see the actual WSDL file we're trying to consume, but it is quite large, and I'm concerned the sheer size of it would make pinpointing the error quite difficult.

I'm hoping that the autogenerated client proxy file and the .NET exception will help someone recognize this WCF Serialization issue.

We've confirmed from our Java vendor that the style of WSDL they generate is doc-literal. After doing some research on the internet, it appears that WCF, by default. translates WSDL files with doc-literal wrapped, and that this may explain, at least in part, why we're seeing this WCF serialization issue with the WSDL file.

I've discovered, through trial and error, that the following attribute decorator in the proxy class file is the culprit behind the serialization issue:

[System.Xml.Serialization.XmlAttributeAttribute()]

If I comment out all instances of this attribute in the proxy class file and rerun my client app, the SOAP message successfully gets sent across the wire and I get a valid web service response come back from the server.

This fix is better than nothing, but I would very much prefer a solution that doesn't require myself or anyone on my team to constantly tweak these .NET autogenerated proxy class files.

I would like to know if there is something I can do, either through the various WCF tools or by modifying the WSDL file, that prevents that [System.Xml.Serialization.XmlAttributeAttribute()] from being applied to my request and response object properties?

Or at least a high level description of WHY we are seeing this serialization behavior in .NET with the Java WSDL file?

thanks in advance, John

解决方案

Use svcutil.exe utility with the /wrapped option on to generate proxy classes.

This will create slightly different classes then those created though Visual Studio in a way described by Ladislav Mrnka here. Resulting proxies should be free from the XmlAttribute issue when using on the client side.

Example:

svcutil /t:code wsdl.xml /out:wsdl.cs /serializer:XmlSerializer /wrapped

这篇关于Java工具创建的WSDL文件的WCF序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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