2012-05-07 24 views
0

我需要接受各种配置文件作为Web服务的输入。Web服务互操作性 - 数据合同中的用户iList是否错误?

[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

这很好。例如下面的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> 

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

相关问题