从客户端Web服务返回NULL

时间:2012-04-11 17:47:03

标签: c# wcf soap

我正在开发一个客户端应用程序,它在c#中使用第三方Web服务(soap)。 肥皂以多个'供应商'节点响应。但是,c#中的数组包含NULL值。 基本上是变量;

SuppliersType[] Suppliers

在其元素中包含NULL值。 但是填充了其他变量(例如响应代码)。 应使用Web服务返回的节点填充Suppliers数组。 我正在使用VS在添加服务引用时生成的类。 我用以下方法打电话给:

ServiceReference2.SuppliersType[] Suppliers;
Client.SupploerProfiles(DTStamp,ID, out ResponseCode, out ResponseMessage, out Suppliers);

我已经包含了WSDL的片段和VS生成的类。 非常感谢任何帮助! 提前致谢! 肥皂反应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tpw="http://www.example.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<tpw:SupplierProfilesResponse>
<DateTimeStamp>2011-01-01 22:22:212</DateTimeStamp>
<ResponseCode>0</ResponseCode>
<ResponseMessage>Success</ResponseMessage>
<Suppliers>
<SupplierName>A</SupplierName>
<SupplierNumber>5559875421</SupplierNumber>
</Suppliers>
<Suppliers>
<SupplierName>B</SupplierName>
<SupplierNumber>5559875421</SupplierNumber>
</Suppliers>
<Suppliers>
<SupplierName>C</SupplierName>
<SupplierNumber>5559875421</SupplierNumber>
</Suppliers>
</tpw:SupplierProfilesResponse>
</soapenv:Body>
</soapenv:Envelope>

WSDL中供应商类型的定义

<xsd:element name="SupplierProfilesResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="DateTimeStamp" type="xsd:dateTime" nillable="true">
</xsd:element>
<xsd:element name="ResponseCode" type="xsd:int" nillable="true">
</xsd:element>
<xsd:element name="ResponseMessage" type="xsd:string" nillable="true">
</xsd:element>
<xsd:element name="Suppliers" type="tns:SuppliersType" minOccurs="0" maxOccurs="7">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="SuppliersType">
<xsd:sequence>
<xsd:element name="SupplierName" type="xsd:string" nillable="true"></xsd:element>
<xsd:element name="SupplierNumber" type="xsd:string" nillable="true"></xsd:element> 
</xsd:sequence>
</xsd:complexType>
</xsd:schema>   
</wsdl:types>

VS生成的类的片段:

[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.example.com")]
public partial class SuppliersType : object, System.ComponentModel.INotifyPropertyChanged
{
private string supplierNameField;
private string supplierNumberField;
 
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true, Order = 0)]
public string SupplierName
{
get
{
return this.supplierNameField;
}
set
{
this.supplierNameField = value;
this.RaisePropertyChanged("SupplierName");
}
}
 
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true, Order = 1)]
public string SupplierNumber
{
get
{
return this.supplierNumberField;
}
set
{
this.supplierNumberField = value;
this.RaisePropertyChanged("SupplierNumber");
}
}
 
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
 
protected void RaisePropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null))
{
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}

1 个答案:

答案 0 :(得分:0)

使用像Fiddler这样的嗅探器来查看即将返回的数据

您还可以使用Disco从URL获取最新的WSDL和相关文件。 然后你可以使用svcutil来构建一个代理类和配置段。 这将有助于您可能需要的错误捕获和其他缓冲区调整

此外,我看不到SuppliersType是一个数组或集合。 在WSDL链接中,它是一个复杂类型,包含2个元素SupplierName和SupplierNumber。 您确定使用的是正确的方法吗? 尝试迪斯科来获得所有类型。