vs 2012使用minOccurs =“0”生成Web服务引用

时间:2013-08-05 18:12:51

标签: .net web-services visual-studio-2012

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

 <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 []参数,Boolean isRequest)          在System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader,MessageVersion version,String action,MessageDescription messageDescription,Object [] parameters,Boolean isRequest)          在System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(消息消息,Object []参数,布尔isRequest)          在System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(消息消息,Object []参数)          在System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc&amp; rpc)          在System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc&amp; rpc)          在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)          在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs)          在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)          在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)       在[0]处重新抛出异常:          在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)          在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData,Int32 type)

1 个答案:

答案 0 :(得分:0)

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