tags:

views:

375

answers:

1

Hi, I have this problem. I have WCF .Net C# web service with this method:

public interface IMyService
{
    // TODO: Add your service operations here
    [OperationContract]
    ListOfRequests GetListOfRequests(string par1,
                                     string par2,
                                     string par3,
                                     DateTime par4,
                                     DateTime par5,
                                     string par6,
                                     string par7);
}
public class MyService : IMyService
{
     public ListOfRequests GetListOfRequests(string par1,
                                 string par2,
                                 string par3,
                                 DateTime par4,
                                 DateTime par5,
                                 string par6,
                                 string par7)
     {
            // .... web method code here;
     }
}

The problem is that when I generate the web service the wsdl schema return this:

<xs:element name="GetListOfRequests">
  <xs:complexType>
   <xs:sequence>
    <xs:element minOccurs="0" name="par1" nillable="true" type="xs:string" /> 
    <xs:element minOccurs="0" name="par2" nillable="true" type="xs:string" /> 
    <xs:element minOccurs="0" name="par3" nillable="true" type="xs:string" /> 
    <xs:element minOccurs="0" name="par4" type="xs:dateTime" /> 
    <xs:element minOccurs="0" name="par5" type="xs:dateTime" /> 
    <xs:element minOccurs="0" name="par6" nillable="true" type="xs:string" /> 
    <xs:element minOccurs="0" name="par7" nillable="true" type="xs:string" /> 
   </xs:sequence>
  </xs:complexType>
  </xs:element>

and I want my parameters to be not null like this:

<xs:element name="GetListOfRequests">
  <xs:complexType>
   <xs:sequence>
    <xs:element minOccurs="1" name="par1" nillable="false" type="xs:string" /> 
    <xs:element minOccurs="1" name="par2" nillable="false" type="xs:string" /> 
    <xs:element minOccurs="1" name="par3" nillable="false" type="xs:string" /> 
    <xs:element minOccurs="1" name="par4" type="xs:dateTime" /> 
    <xs:element minOccurs="1" name="par5" type="xs:dateTime" /> 
    <xs:element minOccurs="1" name="par6" nillable="false" type="xs:string" /> 
    <xs:element minOccurs="0" name="par7" nillable="true" type="xs:string" /> 
   </xs:sequence>
  </xs:complexType>
  </xs:element>

How can I serizalize parameters to achieve this? Thank you in advance for your help. Regards, Georgi

A: 

You can remove

nillable="true"

with

[DataContract]
public class ListOfRequests
{
   DataMember(EmitDefaultValue=false)] 
   public string ListOfRequestsMember;
   // ...
}

The problem here is that the default value of type string is null. So setting this property to false you omit the data when it is set to its default value

In the .NET Framework, types have a concept of default values. For example, for any reference type the default value is null, and for an integer type it is 0. It is occasionally desirable to omit a data member from the serialized data when it is set to its default value. To do this, set the EmitDefaultValue property to false (it is true by default).

ref

Svetlozar Angelov
Hi, Same result. May be I have to explain my app with more detail. I define class with struct. Struct has 10 elements. My web service return object of this class which is my method. The method gets 7 parameters pass them to procedure in my database. This procedure return data set which give the 11 elements their values. So the members of this class are these 11 elements ("packed") in struct which I can easy searilize. The problem is that I can't serialize parameters which my method( which return object of this class) returns. The 11 elements and 8 parameteres are in two diff xsd schemas.
Georgi
As I said this didn't solve my issue.
Georgi