从C#中的Xml SOAP响应中提取值

时间:2014-09-18 17:22:51

标签: c# xml soap

我正在尝试写下代码来读取SOAP响应消息并提取值但没有成功。

我试图从“结构”节点开始提取标量值。

这是我的代码:

        //Extracting the xml http message.

        xmlDoc.LoadXml(xmlHttp.responseText);

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

        nsmgr.AddNamespace("ns", "http://messages.ara.algorithmics.com");

        nsmgr.AddNamespace("ns2", "http://ws.ara.algorithmics.com");            

        XmlElement root = xmlDoc.DocumentElement;

        XmlNode root1 = root.SelectSingleNode("//structure", nsmgr); 

消息看起来像这样:

            <?xml version='1.0' encoding='UTF-8'?>
            <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
            <S:Body>
            <getStructureStatelessResponse xmlns="http://ws.ara.algorithmics.com" xmlns:ns2="http://messages.ara.algorithmics.com">
            <contextId>Interactive_CWMAdmin20140828134101_BASE</contextId>
            <userId>CWMAdminSimulation_10267</userId>
            <parameters>
                <aggregation>a:flat</aggregation>
                <currency>c:usd</currency>
                <depth>2</depth>
                <path requestedValue="portfolio://All%20Portfolios/GROUP">portfolio://actual/GROUP</path>
            </parameters>
            <outputDefs>
                <outputDef definitionId="od0">
                    <outputId>o:Price</outputId>
                    <annualized>false</annualized>
                    <currency>c:usd</currency>
                    <nominalfx>false</nominalfx>
                </outputDef>
                <outputDef definitionId="od1">
                <outputId>o:Value</outputId>
                <annualized>false</annualized>
                <currency>c:usd</currency>
                <nominalfx>false</nominalfx>
                </outputDef>
                <outputDef definitionId="od2">
                <outputId>o:UnitDirtyPrice</outputId>
                <annualized>false</annualized>
                <currency>c:usd</currency>
                <nominalfx>false</nominalfx>
                </outputDef>
            </outputDefs>
            <structure>
                <port childCount="316" expandedNodeName="Position View" name="Position View" nodeId="669">
            <outputResults>
                <scalar ref="od0" value="1.890480805674964E7"/>
                <scalar ref="od1" value="1.890480805674964E7"/>
            <ratio ref="od2" value="NaN"/></outputResults>
            <pos locked="true" name="CF_IF Asset@SPL_ASE@Annuitant mortality improves" nodeId="347" secId="CF_IF Asset@SPL_ASE@Annuitant mortality improves">
            <outputResults>
            <scalar ref="od0" value="0.0"/><scalar ref="od1" value="0.0"/>
            <ratio ref="od2" value="0.0"/></outputResults>
            </pos>
            <pos locked="true" name="CF_IF Asset@SPL_ASE@Assured lives mortality increases" nodeId="359" secId="CF_IF Asset@SPL_ASE@Assured lives mortality increases">

0 个答案:

没有答案