I am working with third party consuming a web service running on an Apache server. There are fields with option minOccurs="0". I used 'add service reference...' command to load the wsdl file. In the final cs file fields with minOccurs="0" are not marked optional. They are treated as regular class member. I then will get error message when I desearilize data returned back without these optional fields. How do I fix this problem?
<complexType name="contactType">
<sequence>
<element minOccurs="0" name="refid" type="ingType32"/>
<element minOccurs="0" name="title" type="csccom:StringType32"/>
<element name="firstname" type="csccom:StringType32"/>
</sequence>
</complexType>
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:csca:xml:ns:csccom-1.1")]
public partial class contactType : object, System.ComponentModel.INotifyPropertyChanged {
private string refidField;
private string titleField;
private string firstnameField;
[System.Xml.Serialization.XmlElementAttribute(DataType="token", Order=0)]
public string refid {
get {
return this.refidField;
}
set {
this.refidField = value;
this.RaisePropertyChanged("refid");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="token", Order=1)]
public string title {
get {
return this.titleField;
}
set {
this.titleField = value;
this.RaisePropertyChanged("title");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="token", Order=2)]
public string firstname {
get {
return this.firstnameField;
}
set {
this.firstnameField = value;
this.RaisePropertyChanged("firstname");
}
}
}
stack trace at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)