2
votes

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)

1
Please post the relevant parts of the WSDL and show the relevant generated code.John Saunders
Exactly what problem do you have if those elements are missing?John Saunders
Error occurred during deserialization process.Luyin Sun
Can you post the stack trace?John Saunders

1 Answers

0
votes

After looking at the raw return data I noticed that there is a data field with nil="true". .NET didn't generate the right code file for this field. The class always expect a datetime value for this field. The service works well after changed the field definition to Nullable. It's not a ideal solution and have to manually do it every time updating service.