2

我正在与使用在 Apache 服务器上运行的 Web 服务的第三方合作。有选项 minOccurs="0" 的字段。我使用“添加服务引用...”命令加载 wsdl 文件。在最终的 cs 文件中 minOccurs="0" 的字段未标记为可选。他们被视为普通班级成员。然后,当我在没有这些可选字段的情况下对返回的数据进行反序列化时,我会收到错误消息。我该如何解决这个问题?

 <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");
        }
    }
}

System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest) 在 System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply( System.ServiceModel.Dispatcher 中的消息消息,Object[] 参数)。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 操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 在 [0] 处重新抛出异常:在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型)

4

1 回答 1

0

查看原始返回数据后,我注意到有一个 nil="true" 的数据字段。.NET 没有为此字段生成正确的代码文件。该类始终期望该字段的日期时间值。将字段定义更改为 Nullable 后,该服务运行良好。这不是一个理想的解决方案,每次更新服务时都必须手动执行。

于 2013-08-07T13:33:24.863 回答