0

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

SuppliersType[] Suppliers

其元素中有 NULL 值。不过,其他变量(例如响应代码)已被填充。供应商数组应填充 Web 服务返回的节点。我正在使用 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));
}
}
}
4

1 回答 1

0

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

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

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

于 2012-04-12T05:38:22.407 回答