Web服务互操作性 - 用户iList在数据合同中是错误的吗?

时间:2012-05-07 11:27:25

标签: wcf web-services

我需要接受各种配置文件作为Web服务的输入。

[DataContract]
public class ProfileRequest
{
    [DataMember]
    public virtual string address { get; set; }

    [DataMember]
    public virtual string type { get; set; }

    [DataMember]
    public virtual string speed { get; set; }
}

我正在考虑使用像这样的IList:

[OperationContract]
IList<ProfileRequest> profiles

它发生在我身上......也许IList并不存在于所有语言中,因此将这样的数据合同暴露出来是不好的做法?我应该只关注简单类型,以便非WCF服务可以更容易地使用该服务吗?

1 个答案:

答案 0 :(得分:1)

这很好。例如以下c#合同:

[DataMember]
    public List<CompositeType> StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }

将在wsdl:

中显示为此xml架构
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/">
<xs:complexType name="CompositeType">
<xs:sequence>
<xs:element minOccurs="0" name="BoolValue" type="xs:boolean"/>
<xs:element minOccurs="0" name="StringValue" nillable="true" type="tns:ArrayOfCompositeType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="CompositeType" nillable="true" type="tns:CompositeType"/>
<xs:complexType name="ArrayOfCompositeType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="CompositeType" nillable="true" type="tns:CompositeType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfCompositeType" nillable="true" type="tns:ArrayOfCompositeType"/>
</xs:schema>

所以这只是消费者的数组。当然,如果您的目标是与特定客户端堆栈的互操作性,则应主动验证互操作性。