Как указать параметр OperationContract как требуется

Интересно, как я могу указать параметр метода OperationContract в WCF как требуется так, чтобы сгенерированный xsd содержал minOccurs = "1" вместо minOccurs = "0".

Пример:

[ServiceContract(Namespace = "http://myUrl.com")]  
public interface IMyWebService  
{  
   [OperationContract]  
   string DoSomething(string param1, string param2, string param3);  
}

генерирует этот xsd:

<xs:element name="DoSomething">  
  <xs:complexType>  
    <xs:sequence>  
      <xs:element minOccurs="0" name="param1" nillable="true" type="xs:string" />  
      <xs:element minOccurs="0" name="param2" nillable="true" type="xs:string" />  
      <xs:element minOccurs="0" name="param3" nillable="true" type="xs:string" />  
    </xs:sequence>  
  </xs:complexType>  

Но я хочу определить minOccurs = "1" в рамках кода без необходимости вручную зафиксировать его в xsd файле.

6
задан Jan-Patrick Ahnen 4 August 2010 в 14:33
поделиться

1 ответ

Вам может потребоваться обернуть ваши параметры в класс, тогда вы можете использовать атрибут DataMember и указать IsRequired = true :

[ServiceContract(Namespace = "http://myUrl.com")]  
public interface IMyWebService  
{  
   [OperationContract]  
   string DoSomething(RequestMessage request);  
}

[DataContract]
public class RequestMessage
{
   [DataMember(IsRequired = true)]
   public string param1 { get; set; }

   [DataMember(IsRequired = true)]
   public string param3 { get; set; }

   [DataMember(IsRequired = true)]
   public string param3 { get; set; }
}
9
ответ дан 9 December 2019 в 20:38
поделиться
Другие вопросы по тегам:

Похожие вопросы: