質問

私は、必要に応じてIが生成されたXSDはのminOccurs =「1」の代わりにminOccurs属性の「0」

を含むようにWCFでOperationContractメソッドのパラメータを指定することができるか疑問

例:

[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>  

しかし、私は手動に必要とすることなく、コード内=「1」minOccurs属性を定義するXSDファイルでそれを修正したい。

役に立ちましたか?

解決

あなたは、あなたが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; }
}

他のヒント

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top