WCF - Missing integer parameter processed as 0

I am using WCF to create a SOAP Webservice, and now I am facing the following problem:

  • I have an OperationContract defined that looks like this:

[OperationContract] void InsertSomeData(string version, int someId);

  • When testing the service using soapUI, I realized that if I remove someId tags in the request, I get a value of 0 in my service
  • Is this standard behavior? In fact, I would suggest that the service threw some kind of exception, since the parameter cannot be null.
  • Can I distinguish my service between 0 as the real value that was transmitted and just the missing tags, or do I need to set all my parameters to zero in advance.

Thank you for your help.

+4
source share
1 answer

Hacking Method:

 [OperationContract] public void InsertSomeData(MyData data){...} [DataContract] public class MyData{ [DataMember] public string version{get;set;} [DataMember(IsRequired=true)] public int someId{get;set;} } 

A longer but better way: http://thorarin.net/blog/post/2010/08/08/Controlling-WSDL-minOccurs-with-WCF.aspx

+4
source

Source: https://habr.com/ru/post/1446953/


All Articles