How to serialize parameters in Web Service method

Posted by Georgi on Stack Overflow See other posts from Stack Overflow or by Georgi
Published on 2009-10-20T12:41:44Z Indexed on 2010/03/28 4:03 UTC
Read the original article Hit count: 601

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf