0

I prepared WCF service according to spec I've get. It works OK. I have one method, decorated with [OperationContract] called Search.

It looks like this (I've changed custom types names, but it doesn't matter) :

SearchResult Search(SearchCritery searchCritery, string connectionWith);

After that I get wsdl, which is OK too. But, one thing is wrong :

<xs:element name="Search">
<xs:complexType>
    <xs:sequence>
        <xs:element type="q1:SearchCritery" name="searchCritery" nillable="true" minOccurs="0" xmlns:q1="someCustomSchema"/>
        <xs:element type="xs:string" name="connectionWith" nillable="true" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

as you can see, both input paramteres are marked as nillable and not required. What can I do, to change in my code to make them required and not nullable. Of course I'm checking in my code if they aren't and return appropriate info about it, but I must show in wsdl that. Another thing is, that I can't change this method and params declaration (types etc.)

Any help will be valuable.

EDITED: (DataContract added)

Filed names are simplified for question purpose

 [DataContract]
public class SearchCritery
{
    public SearchCritery()
    { }

    [Power(6)]
    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
    public string FieldA { get; set; }

    [Power(5)]
    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 1)]
    public string FieldB { get; set; }

    [Power(1)]
    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 2)]
    public string FieldC { get; set; }

    [Power(5)]
    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 3)]
    public string FieldD { get; set; }

}

As you see, the second parameters - string, isn't in Datacontract because I didn't know ho3 to add "only string" as data contract member.

Marcin
  • 427
  • 7
  • 21
  • Can you show your data contract definitions? – spodger Oct 04 '17 at 10:26
  • Sure, see my question update – Marcin Oct 04 '17 at 10:36
  • 1
    You're probably best off starting here https://stackoverflow.com/questions/1438623/how-can-i-force-wcf-to-autogenerate-wsdls-with-required-method-parameters-minoc/3436039#3436039 – spodger Oct 04 '17 at 11:51
  • I had forgotten that when this was an issue for me, a few years ago, we were working using a schema first process then generating and hand-crafting the WSDLs. – spodger Oct 04 '17 at 11:52
  • @spodger I think, that your link to blog post will helps me :) I must test it for sure, but it looks very promising – Marcin Oct 04 '17 at 12:26

0 Answers0