我有一个webservices,我已经将它添加到我的.NET项目中作为web参考。其中一种web方法返回一个嵌套数组(NameValuePairDTOArray [NameValuePairDTO [])。我只能在.NET代码中获得空对象,但是当我通过SoapUI测试时它确实返回了数据。.NET调用webservices并返回空值
我在这里粘贴了一部分wsdl文件。
这是方法定义。
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://services.mymachine.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IneteractionService" targetNamespace="http://services.mymachine.com/">
<operation name="getValue" parameterOrder="parameters">
<input message="tns:MyServices_getValues"/>
<output message="tns:MyServices_getValuesResponse"/>
<fault message="tns:ServiceException" name="ServiceException"/>
</operation>
<xs:schema xmlns:ns1="http://ods.mymachine.com/v1_0_0" xmlns:tns="http://services.mymachine.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://services.mymachine.com/" version="1.0">
<xs:import namespace="http://ods.mymachine.com/v1_0_0"/>
<xs:element name="ServiceException" type="tns:ServiceException"/>
<xs:element name="getValue" type="tns:getValue"/>
<xs:element name="getValuesResponse" type="tns:getValuesResponse"/>
<xs:complexType name="getValue">
<xs:sequence>
<xs:element minOccurs="0" name="firstName" type="xs:string"/>
<xs:element minOccurs="0" name="lastName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getValuesResponse">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="ns1:NameValuePairDTOArray"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</definitions>
这是响应数据的定义。
<xs:schema xmlns:ns1="http://common.mymanchine.com/v1_0_0" xmlns:tns="http://ods.mymachine.com/v1_0_0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://ods.mymachine.com/v1_0_0" version="1.0">
<xs:import namespace="http://common.mymanchine.com/v1_0_0"/>
<xs:complexType final="#all" name="NameValuePairDTOArray">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="tns:NameValuePairDTO"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="NameValuePairDTO">
<xs:complexContent>
<xs:extension base="ns1:DataTransferObject">
<xs:sequence/>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema
由.NET生成的代理类是这样的:
[WebServiceBinding(Name = "InteractionServicesBinding", Namespace = "http://services.mymachine.com/")]
[XmlInclude(typeof(DataTransferObject))]
[DebuggerStepThrough]
[GeneratedCode("System.Web.Services", "4.0.30319.1")]
[DesignerCategory("code")]
public class InteractionServicesServiceWse : WebServicesClientProtocol
{
public InteractionServicesServiceWse();
[SoapDocumentMethod("", RequestNamespace = "http://services.mymachine.com/",
ResponseNamespace = "http://services.services.mymachine.com/", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public NameValuePairDTOArray[] getValue(string firstName, string lastName);
}
[Serializable]
[XmlType(Namespace = "http://ods.mymachine.com/v1_0_0")]
[GeneratedCode("System.Xml", "4.0.30319.233")]
[DebuggerStepThrough]
[DesignerCategory("code")]
public class NameValuePairDTOArray
{
public NameValuePairDTOArray();
[XmlElement("item", IsNullable = true)]
public NameValuePairDTO[] item { get; set; }
}
[Serializable]
[DesignerCategory("code")]
[XmlType(Namespace = "http://ods.mymachine.com/v1_0_0")]
[GeneratedCode("System.Xml", "4.0.30319.233")]
[DebuggerStepThrough]
public class NameValuePairDTO : DataTransferObject
{
public NameValuePairDTO();
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string value { get; set; }
}
现在如果我叫的getValue( “约翰福音”, “彼得”),它会如下面的.NET返回。
但soapUI的返回是这样的:
<env:Body>
<ns2:getValueResponse xmlns:ns2="http://services.mymachine.com/">
<return>
<item value="123" name="BONUS_ID"/>
<item value="456" name="POPUP_OBJECT_ID"/>
</return>
<return>
<item value="123" name="BONUS_ID"/>
<item value="567" name="POPUP_OBJECT_ID"/>
</return>
</ns2:getValueResponse>
</env:Body>
看来,.NET不能检测NameValuePairDTO /产品阵列。
怎么了?
自添加服务参考以来,您是否对服务进行过任何更改? – cadrell0