Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当使用带有C#get null的soapweb服务时,提供程序是Ladon/Python_C#_Python_Soap_Ladon - Fatal编程技术网

当使用带有C#get null的soapweb服务时,提供程序是Ladon/Python

当使用带有C#get null的soapweb服务时,提供程序是Ladon/Python,c#,python,soap,ladon,C#,Python,Soap,Ladon,我正在尝试使用C#来使用SOAP web服务,虽然在使用SOAPUI或甚至在使用Python和SUD时看起来还可以(我想确定它不在服务器端),但当从C#使用它时,我总是得到空值(而使用Fiddler的截取显示它实际上包含数据) 可能是SOAP数组被C#创建的代理对象处理不良 由于我不熟悉WSDL,我可能错过了一些东西,我在web上看到了许多关于类似(与Ladon部分无关)问题的解决方法,但没有一个是有用的 谢谢你的帮助 ps:一些代码可以重现这个错误 步骤0:添加:服务Web引用,如下所述:

我正在尝试使用C#来使用SOAP web服务,虽然在使用SOAPUI或甚至在使用Python和SUD时看起来还可以(我想确定它不在服务器端),但当从C#使用它时,我总是得到空值(而使用Fiddler的截取显示它实际上包含数据)

可能是SOAP数组被C#创建的代理对象处理不良

由于我不熟悉WSDL,我可能错过了一些东西,我在web上看到了许多关于类似(与Ladon部分无关)问题的解决方法,但没有一个是有用的

谢谢你的帮助


ps:一些代码可以重现这个错误

步骤0:添加:服务Web引用,如下所述: 我的名字叫“albumsWRn”

C#此错误的演示如下:

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using ConsoleApplication6.albumsWRn;    // PUT HERE THE NAME OF THE "Web References" you provide @ step 0

namespace ConsoleApplication6
{
    public static class PrettyPrinter
    {
    // from: http://www.jberndsen.nl/2012/05/c-pretty-printer/

    // the main function to be called to pretty print an object
    public static void PrettyPrint(object myData, StreamWriter sw)
    {
        // output to StreamWriter, in our case, representing a text file
        if (sw == null) throw new ArgumentNullException("sw");
        sw.WriteLines(GetPropValues(myData));
    }

    // to standard output
    public static void PrettyPrint(object myData)
    {
        StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
        sw.AutoFlush = true;
        Console.SetOut(sw);
        PrettyPrint(myData, sw);
    }

    // extension for the streamwriter to write lists of strings
    private static void WriteLines(this StreamWriter sw, IEnumerable<string> lines)
    {
        foreach (var line in lines)
        {
        sw.WriteLine(line);
        }
    }

    // generates spaces for indentation
    private static string Spaces(int i)
    {
        return (i > 0) ? "    " + Spaces(i - 1) : string.Empty;
    }


    private static string GetValue(object o)
    {
        if (o == null)
        {
        return "null";
        }
        if (o is DateTime)
        {
        return ((DateTime)o).ToShortDateString();
        }
        return o.ToString();
    }


    private static List<string> GetPropValues(object element, int depth = 0)
    {
        var result = new List<string>();
        // primitives
        if (element == null || element is ValueType || element is string)
        {
        result.Add(Spaces(depth) + GetValue(element));
        }
        else
        {
        // enumerations        
        var enumerableElement = element as IEnumerable;
        if (enumerableElement != null)
        {
            foreach (var item in enumerableElement)
            {
            result.AddRange(GetPropValues(item, depth + 1));
            }
        }
        // composite types         
        else
        {
            // get all the members and iterate through them
            var members = element.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance);
            foreach (var member in members)
            {
            var fieldInfo = member as FieldInfo;
            var propertyInfo = member as PropertyInfo;
            if (fieldInfo != null || propertyInfo != null)
            {
                // get the type of the member and check if its a primitive
                var t = fieldInfo != null ? fieldInfo.FieldType : propertyInfo.PropertyType;
                if (t.IsValueType || t == typeof(string))
                {
                // print the primitive member, its name and its value  
                var localResult = member.Name + ": ";
                localResult += GetValue(fieldInfo != null ? fieldInfo.GetValue(element) : propertyInfo.GetValue(element, null));
                result.Add(Spaces(depth) + localResult);
                }
                else
                {
                // print the non-primitive member, its name and recursively pretty print its value
                var o = fieldInfo != null ? fieldInfo.GetValue(element) : propertyInfo.GetValue(element, null);
                result.Add(Spaces(depth) + member.Name + ": ");
                result.AddRange(GetPropValues(o, depth + 1));
                }
            }
            }
        }
        }
        return result;
    }

    }

    class Program
    {
    static void Main(string[] args)
    {
        AlbumService albumService = new AlbumService();
        var filteredAlbums = albumService.listAlbums("The");
        PrettyPrinter.PrettyPrint(filteredAlbums);
        if (filteredAlbums.item == null)
        {
        Console.WriteLine("null contained, while it should not!");
        }
    }
    }
}
使用系统;
使用系统集合;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
运用系统反思;
使用系统文本;
使用ConsoleApplication6.albumsWRn;//在此处输入您在步骤0中提供的“Web引用”的名称
命名空间控制台应用程序6
{
公共静态类预印字机
{
//发件人:http://www.jberndsen.nl/2012/05/c-pretty-printer/
//要调用的主要函数以漂亮地打印对象
公共静态无效预打印(对象myData,StreamWriter sw)
{
//在本例中,输出到StreamWriter,表示一个文本文件
如果(sw==null)抛出新的ArgumentNullException(“sw”);
sw.WriteLines(GetPropValues(myData));
}
//到标准输出
公共静态无效预打印(对象myData)
{
StreamWriter sw=新的StreamWriter(Console.OpenStandardOutput());
sw.AutoFlush=true;
控制台放样(sw);
预打印(myData,sw);
}
//streamwriter写入字符串列表的扩展
专用静态无效写入线(此StreamWriter sw,IEnumerable lines)
{
foreach(行中的var行)
{
西南写入线(行);
}
}
//为缩进生成空间
私有静态字符串空间(int i)
{
return(i>0)?“”+空格(i-1):string.Empty;
}
私有静态字符串GetValue(对象o)
{
如果(o==null)
{
返回“null”;
}
if(o是日期时间)
{
return((DateTime)o.ToShortDateString();
}
返回o.ToString();
}
私有静态列表GetPropValues(对象元素,int depth=0)
{
var result=新列表();
//原语
if(element==null | | element为ValueType | | element为string)
{
添加(空格(深度)+GetValue(元素));
}
其他的
{
//枚举
var enumerableElement=元素为IEnumerable;
if(enumerableElement!=null)
{
foreach(enumerableElement中的变量项)
{
AddRange(GetPropValues(项目,深度+1));
}
}
//复合类型
其他的
{
//获取所有成员并遍历它们
var members=element.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance);
foreach(成员中的var成员)
{
var fieldInfo=作为fieldInfo的成员;
var propertyInfo=作为propertyInfo的成员;
if(fieldInfo!=null | | propertyInfo!=null)
{
//获取成员的类型并检查其是否为基元
var t=fieldInfo!=null?fieldInfo.FieldType:propertyInfo.PropertyType;
if(t.IsValueType | | t==typeof(string))
{
//打印基本体成员及其名称和值
var localResult=member.Name+“:”;
localResult+=GetValue(fieldInfo!=null?fieldInfo.GetValue(元素):propertyInfo.GetValue(元素,null));
添加(空格(深度)+localResult);
}
其他的
{
//打印非原语成员及其名称,并递归打印其值
var o=fieldInfo!=null?fieldInfo.GetValue(元素):propertyInfo.GetValue(元素,null);
结果.添加(空格(深度)+成员.名称+“:”);
AddRange(GetPropValues(o,深度+1));
}
}
}
}
}
返回结果;
}
}
班级计划
{
静态void Main(字符串[]参数)
{
AlbumService AlbumService=新AlbumService();
var filteredAlbums=albumService.listAlbums(“The”);
预印字机。预印字(滤色片);
if(filteredAlbums.item==null)
{
WriteLine(“包含null,但不应包含它!”);
}
}
}
}
soapUI:这是使用soapUI检查实际工作情况时使用的查询

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:AlbumService">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:listAlbums soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <search-frase xsi:type="xsd:string">The</search-frase>
      </urn:listAlbums>
   </soapenv:Body>
</soapenv:Envelope>

这个
WSDL可在此处查看: (这是Ladon创建者提供的演示站点:)


获取与搜索框匹配的相册列表
获取与搜索框匹配的相册列表
Ladon生成的服务定义
用Fiddler截获的答案(因此,它不是空的):


<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:AlbumService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="urn:AlbumService" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="urn:AlbumService" name="AlbumService">
   <wsdl:types>
      <xsd:schema targetNamespace="urn:AlbumService">
     <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
     <xsd:complexType name="ArrayOfunicode">
        <xsd:sequence>
           <xsd:element type="xsd:string" name="item" nillable="true" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
     </xsd:complexType>
     <xsd:complexType name="Band">
        <xsd:sequence>
           <xsd:element type="ns2:ArrayOfunicode" name="album-titles" nillable="true" minOccurs="0" maxOccurs="1" />
           <xsd:element type="xsd:string" name="name" minOccurs="1" maxOccurs="1" />
        </xsd:sequence>
     </xsd:complexType>
     <xsd:complexType name="Album">
        <xsd:sequence>
           <xsd:element type="ns2:Band" name="band" minOccurs="1" maxOccurs="1" />
           <xsd:element type="ns2:ArrayOfunicode" name="songs" nillable="true" minOccurs="0" maxOccurs="1" />
           <xsd:element type="xsd:string" name="title" minOccurs="1" maxOccurs="1" />
        </xsd:sequence>
     </xsd:complexType>
     <xsd:complexType name="ArrayOfAlbum">
        <xsd:sequence>
           <xsd:element type="ns2:Album" name="item" nillable="true" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
     </xsd:complexType>
     <xsd:complexType name="ArrayOfBand">
        <xsd:sequence>
           <xsd:element type="ns2:Band" name="item" nillable="true" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
     </xsd:complexType>
      </xsd:schema>
   </wsdl:types>
   <wsdl:message name="listAlbums">
      <wsdl:part type="xsd:string" name="search-frase" />
   </wsdl:message>
   <wsdl:message name="listAlbumsResponse">
      <wsdl:part type="ns2:ArrayOfAlbum" name="result" />
   </wsdl:message>
   <wsdl:message name="listBands">
      <wsdl:part type="xsd:string" name="search-frase" />
   </wsdl:message>
   <wsdl:message name="listBandsResponse">
      <wsdl:part type="ns2:ArrayOfBand" name="result" />
   </wsdl:message>
   <wsdl:portType name="AlbumServicePortType">
      <wsdl:operation name="listAlbums">
     <wsdl:documentation>Fetch a list of albums matching search_frase</wsdl:documentation>
     <wsdl:input message="tns:listAlbums" />
     <wsdl:output message="tns:listAlbumsResponse" />
      </wsdl:operation>
      <wsdl:operation name="listBands">
     <wsdl:documentation>Fetch a list of albums matching search_frase</wsdl:documentation>
     <wsdl:input message="tns:listBands" />
     <wsdl:output message="tns:listBandsResponse" />
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding type="tns:AlbumServicePortType" name="AlbumService">
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
      <wsdl:operation name="listAlbums">
     <soap:operation style="rpc" soapAction="http://ladonize.org/python-demos/AlbumService/soap11/listAlbums" />
     <wsdl:input>
        <soap:body namespace="urn:AlbumService" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
     </wsdl:input>
     <wsdl:output>
        <soap:body namespace="urn:AlbumService" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
     </wsdl:output>
      </wsdl:operation>
      <wsdl:operation name="listBands">
     <soap:operation style="rpc" soapAction="http://ladonize.org/python-demos/AlbumService/soap11/listBands" />
     <wsdl:input>
        <soap:body namespace="urn:AlbumService" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
     </wsdl:input>
     <wsdl:output>
        <soap:body namespace="urn:AlbumService" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
     </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="AlbumService">
      <wsdl:documentation>Ladon generated service definition</wsdl:documentation>
      <wsdl:port name="AlbumService" binding="tns:AlbumService">
     <soap:address location="http://ladonize.org/python-demos/AlbumService/soap11" />
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns="urn:AlbumService" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <ns:listAlbumsResponse>
     <result>
        <item>
           <band>
          <album-titles>
             <item>Album Of The Year</item>
             <item>KING FOR A DAY - FOOL FOR A LIFETIME</item>
          </album-titles>
          <name>Faith No More</name>
           </band>
           <title>Album Of The Year</title>
           <songs>
          <item>Ashes To Ashes.mp3</item>
          <item>Mouth To Mouth.mp3</item>
          <item>Last Cup Of Sorrow [Sharam Versus Fnm Club Mix] [Bonus Track].mp3</item>
          <item>Paths Of Glory.mp3</item>
          <item>Pristina.mp3</item>
          <item>Light Up And Let Go [Bonus Track].mp3</item>
          <item>Helpless.mp3</item>
          <item>The Big Kahuna [Bonus Track].mp3</item>
          <item>She Loves Me Not.mp3</item>
          <item>Stripsearch.mp3</item>
          <item>Last Cup Of Sorrow.mp3</item>
          <item>Collision.mp3</item>
          <item>Home Sick Home.mp3</item>
          <item>She Loves Me Not [Spinna Crazy Dub Mix] [Bonus Track].mp3</item>
          <item>Last Cup Of Sorrow [Rammstein Mix] [Bonus Track].mp3</item>
          <item>Naked In Front of The Computer.mp3</item>
          <item>Got That Feeling.mp3</item>
          <item>Ashes To Ashes [Hardknox Alternative Mix] [Bonus Track].mp3</item>
           </songs>
        </item>
        <item>
           <band>
          <album-titles>
             <item>Paint The Sky With Stars - The Best Of Enya</item>
          </album-titles>
          <name>Enya</name>
           </band>
           <title>Paint The Sky With Stars - The Best Of Enya</title>
           <songs>
          <item>Watermark.mp3</item>
          <item>Boadicea.mp3</item>
          <item>Storms In Africa.mp3</item>
          <item>Book Of Days.mp3</item>
          <item>Caribben Blue.mp3</item>
          <item>The Celts.mp3</item>
          <item>Anywhere Is.mp3</item>
          <item>Shepherd Moons.mp3</item>
          <item>China Roses.mp3</item>
          <item>Marble Halls.mp3</item>
          <item>On My Way Home.mp3</item>
          <item>Ebudae.mp3</item>
          <item>The Memory Of Trees.mp3</item>
          <item>Paint The Sky With Stars.mp3</item>
          <item>Only If....mp3</item>
          <item>Orinoco Flow.mp3</item>
           </songs>
        </item>
        <item>
           <band>
          <album-titles>
             <item>Zitilites</item>
             <item>No Balance Palace</item>
             <item>Home Dead</item>
             <item>Travelogue</item>
             <item>Cruzential</item>
             <item>The Good Life</item>
          </album-titles>
          <name>Kashmir</name>
           </band>
           <title>The Good Life</title>
           <songs>
          <item>Gorgeous.mp3</item>
          <item>New Year's Eve.mp3</item>
          <item>Lampshade.mp3</item>
          <item>It's OK Now.mp3</item>
          <item>Graceland.mp3</item>
          <item>Miss You.mp3</item>
          <item>Mudbath.mp3</item>
          <item>Mom In Love, Daddy In Space.mp3</item>
          <item>Kiss Me Goodbye.mp3</item>
          <item>Make It Grand.mp3</item>
           </songs>
        </item>
        <item>
           <band>
          <album-titles>
             <item>The Wall CD2</item>
             <item>The Wall Part I</item>
          </album-titles>
          <name>Pink Floyd</name>
           </band>
           <title>The Wall CD2</title>
           <songs>
          <item>Nobody Home.mp3</item>
          <item>Waiting For The Worms.mp3</item>
          <item>Bring The Boys Back Home.mp3</item>
          <item>The Trial.mp3</item>
          <item>Is There Anybody Out There?.mp3</item>
          <item>Comfortably Numb.mp3</item>
          <item>Run Like Hell.mp3</item>
          <item>The Show Must Go On.mp3</item>
          <item>Vera.mp3</item>
          <item>In The Flesh.mp3</item>
          <item>Outside The Wall.mp3</item>
          <item>Hey You.mp3</item>
          <item>Stop.mp3</item>
           </songs>
        </item>
        <item>
           <band>
          <album-titles>
             <item>The Wall CD2</item>
             <item>The Wall Part I</item>
          </album-titles>
          <name>Pink Floyd</name>
           </band>
           <title>The Wall Part I</title>
           <songs>
          <item>The Happiest Days Of Our Lives.mp3</item>
          <item>Another Brick In The Wall (Part 1).mp3</item>
          <item>Goodbye Cruel World.mp3</item>
          <item>One Of The Turns.mp3</item>
          <item>In The Flesh?.mp3</item>
          <item>Empty Spaces.mp3</item>
          <item>The Thin Ice.mp3</item>
          <item>Goodbye Blue Sky.mp3</item>
          <item>Another Brick In The Wall (Part 2).mp3</item>
          <item>Another Brick In The Wall (Part 3).mp3</item>
          <item>Young Lust.mp3</item>
          <item>Mother.mp3</item>
          <item>Don't Leave Now.mp3</item>
           </songs>
        </item>
     </result>
      </ns:listAlbumsResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>