"< Name xmlns =''>没想到。在C#中反序列化SOAP响应时获取错误? [英] "<Name xmlns=''> was not expected. Error getting during deserialize SOAP response in C#?

查看:69
本文介绍了"< Name xmlns =''>没想到。在C#中反序列化SOAP响应时获取错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的wsdl.exe生成的存根类



Below is my stub classes generated by wsdl.exe

[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("entries", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public partial mapEntry[] args {
    get {
        return this.argsField;
    }
    set {
        this.argsField = value;
    }
}





第二类





Second Class

[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://webservice.api.cabaret.com/")]
public partial class callArgs {

    private string nameField;

    private mapEntry[] argsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute("entries", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public mapEntry[] args {
        get {
            return this.argsField;
        }
        set {
            this.argsField = value;
        }
    }
}

Below is my response SOAP XML

<pre lang="XML">

<name>signatures</name>
<value xsi:type="ns2:map" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<entries><value xsi:type="ns2:map">
<entries>
<name>type</name>
<value xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">signature</value>
</entries>
<entries>
<name>state</name>
<value xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">3</value>
</entries>





在这个过程中,我得到了没想到。错误。我是如何解决这个错误的?我在哪里做错了?请帮我解决这个错误。



我尝试过:



下面我尝试将SOAP XML反序列化为对象





During this process I got the " was not expected. error. How I resolved this error? Where I am doing wrong in it? Please help me to resolve this error.

What I have tried:

Below I tried to Deserialize the SOAP XML to Object

XmlRootAttribute xRoot = new XmlRootAttribute("callArgs");
            xRoot.ElementName = "name";
            xRoot.Namespace = "http://webservice.api.cabaret.com/";
            xRoot.IsNullable = true;
            System.IO.StringReader stringReader = new System.IO.StringReader(ValidatePDF[5].InnerXml);
            XmlSerializer deserializer = new XmlSerializer(typeof(callArgs),xRoot);
            callArgs devicesResult = (callArgs)deserializer.Deserialize(stringReader);

推荐答案

好吧, XmlSerializer 本身非常糟糕且过时,处理起来并不乐趣(比如基于数据协定的序列化)。但是使用SOAP,你别无选择,只能使用SOAP规则,即使它们非常糟糕。我不知道你在哪里做。特别是,我看不到你在哪里使用 SoapFormatter 类:

SoapFormatter Class(System.Runtime.Serialization.Formatters.Soap) [ ^ ]。



参见:

使用Soap Formatter进行.NET序列化 [ ^ ],

XML和SOAP序列化 [ ^ ]。



-SA
Well, XmlSerializer is itself pretty bad and outdated, not fun to deal with (compared, say, to data contract based serialization). But with SOAP you have no choice but playing by SOAP rules, even though they are quite bad. And I don't see where you do it. In particular, I cannot see where you use SoapFormatter class:
SoapFormatter Class (System.Runtime.Serialization.Formatters.Soap)[^].

See also:
.NET Serialization using Soap Formatter [^],
XML and SOAP Serialization[^].

—SA


这篇关于&quot;&lt; Name xmlns =''&gt;没想到。在C#中反序列化SOAP响应时获取错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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