【发布时间】:2013-08-06 13:21:21
【问题描述】:
我正在与使用在 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 阅读器,MessageVersion 版本,XmlSerializer 序列化程序,MessagePartDescription returnPart,MessagePartDescriptionCollection bodyParts,Object[] 参数,布尔 isRequest) 在 System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader 阅读器,MessageVersion 版本,字符串操作,MessageDescription messageDescription,Object[] 参数,布尔 isRequest) 在 System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(消息消息,对象 [] 参数,布尔 isRequest) 在 System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(消息消息,对象 [] 参数) 在 System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc) 在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc& rpc) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用,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& msgData, Int32 类型)
【问题讨论】:
-
请贴出 WSDL 的相关部分并显示相关生成的代码。
-
如果缺少这些元素,您到底有什么问题?
-
反序列化过程中发生错误。
-
你能发布堆栈跟踪吗?
标签: .net web-services visual-studio-2012