gpt4 book ai didi

c# - 序列化通过 SOAP 发送的对象

转载 作者:行者123 更新时间:2023-11-30 21:47:56 28 4
gpt4 key购买 nike

我正在处理一些对 Microsoft CRM 的 SOAP 请求/响应,我正试图将其保存下来。我尝试序列化的 Response 对象是 Microsoft.Xrm.Sdk.Metadata.OptionSetMetadataBase ( https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.metadata.optionsetmetadata.aspx )。当我尝试使用此扩展方法序列化我的对象时:

public static string Serialize(this IExtensibleDataObject obj, bool indent = false)
{
NetDataContractSerializer contractSerializer = new NetDataContractSerializer();
using (StringWriter stringWriter = new StringWriter((IFormatProvider) CultureInfo.InvariantCulture))
{
using (XmlTextWriter xmlTextWriter = new XmlTextWriter((TextWriter) stringWriter))
{
if (indent)
{
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.Indentation = 2;
}
contractSerializer.WriteObject((XmlWriter) xmlTextWriter, (object) obj);
return stringWriter.ToString();
}
}
}

我收到这个错误:

threw an exception of type 'System.Runtime.Serialization.InvalidDataContractException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233088
HelpLink: null
InnerException: null
Message: "Type 'Microsoft.Xrm.Sdk.Metadata.OptionMetadataCollection' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types."
Source: "System.Runtime.Serialization"
StackTrace: "at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
at System.Runtime.Serialization.DataContract.ThrowTypeNotSerializable(Type type)
at System.Runtime.Serialization.CollectionDataContract.GetValidContract(SerializationMode mode)
at System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContract(Int32 id, RuntimeTypeHandle typeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.GetDataContract(Int32 id, RuntimeTypeHandle typeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at WriteOptionSetMetadataToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )
at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.NetDataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContract contract, Hashtable surrogateDataContracts)
at System.Runtime.Serialization.NetDataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.NetDataContractSerializer.WriteObject(XmlWriter writer, Object graph)
at DLaB.Common.Extensions.Serialize(IExtensibleDataObject obj, Boolean indent)"
TargetSite: {Void ThrowInvalidDataContractException(System.String, System.Type)}

我认为这是可能的,因为我刚刚通过 SOAP 请求检索到此信息,因此它只是反序列化。如果有帮助,这里是 Soap Response:

<ExecuteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
<ExecuteResult xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:ResponseName>RetrieveAllOptionSets</b:ResponseName>
<b:Results xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<b:KeyValuePairOfstringanyType>
<c:key>OptionSetMetadata</c:key>
<c:value i:type="d:ArrayOfOptionSetMetadataBase" xmlns:d="http://schemas.microsoft.com/xrm/2011/Metadata">
<d:OptionSetMetadataBase i:type="d:OptionSetMetadata">
<d:MetadataId>0872a2b1-6db1-48a9-8aa2-1686f294b1e0</d:MetadataId>
<d:HasChanged i:nil="true"/>
<d:Description>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Need type</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Need type</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Description>
<d:DisplayName>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Need</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Need</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:DisplayName>
<d:IsCustomOptionSet>false</d:IsCustomOptionSet>
<d:IsCustomizable>
<b:CanBeChanged>false</b:CanBeChanged>
<b:ManagedPropertyLogicalName>iscustomizable</b:ManagedPropertyLogicalName>
<b:Value>true</b:Value>
</d:IsCustomizable>
<d:IsGlobal>true</d:IsGlobal>
<d:IsManaged>true</d:IsManaged>
<d:Name>need</d:Name>
<d:OptionSetType>Picklist</d:OptionSetType>
<d:IntroducedVersion>5.0.0.0</d:IntroducedVersion>
<d:Options>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Must have</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Must have</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>0</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Should have</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Should have</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>1</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Good to have</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Good to have</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>2</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>No need</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>No need</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>3</d:Value>
</d:OptionMetadata>
</d:Options>
</d:OptionSetMetadataBase>
<d:OptionSetMetadataBase i:type="d:OptionSetMetadata">
<d:MetadataId>3041d03c-4166-4814-a2d4-1e3d93caf2f1</d:MetadataId>
<d:HasChanged i:nil="true"/>
<d:Description>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Categories for connection roles.</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Categories for connection roles.</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Description>
<d:DisplayName>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Category</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Category</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:DisplayName>
<d:IsCustomOptionSet>false</d:IsCustomOptionSet>
<d:IsCustomizable>
<b:CanBeChanged>false</b:CanBeChanged>
<b:ManagedPropertyLogicalName>iscustomizable</b:ManagedPropertyLogicalName>
<b:Value>true</b:Value>
</d:IsCustomizable>
<d:IsGlobal>true</d:IsGlobal>
<d:IsManaged>true</d:IsManaged>
<d:Name>connectionrole_category</d:Name>
<d:OptionSetType>Picklist</d:OptionSetType>
<d:IntroducedVersion>5.0.0.0</d:IntroducedVersion>
<d:Options>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Business</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Business</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>1</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Family</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Family</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>2</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Social</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Social</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>3</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Sales</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Sales</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>4</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Other</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Other</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>5</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Stakeholder</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Stakeholder</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>1000</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Sales Team</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Sales Team</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>1001</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Service</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Service</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>1002</d:Value>
</d:OptionMetadata>
</d:Options>
</d:OptionSetMetadataBase>
<d:OptionSetMetadataBase i:type="d:OptionSetMetadata">
<d:MetadataId>8e76ca1c-8d7c-45d2-b870-25b108a31792</d:MetadataId>
<d:HasChanged i:nil="true"/>
<d:Description>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>If there has been initial communication with this lead.</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>If there has been initial communication with this lead.</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Description>
<d:DisplayName>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Initial Communication</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Initial Communication</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:DisplayName>
<d:IsCustomOptionSet>false</d:IsCustomOptionSet>
<d:IsCustomizable>
<b:CanBeChanged>false</b:CanBeChanged>
<b:ManagedPropertyLogicalName>iscustomizable</b:ManagedPropertyLogicalName>
<b:Value>true</b:Value>
</d:IsCustomizable>
<d:IsGlobal>true</d:IsGlobal>
<d:IsManaged>true</d:IsManaged>
<d:Name>initialcommunication</d:Name>
<d:OptionSetType>Picklist</d:OptionSetType>
<d:IntroducedVersion>5.0.0.0</d:IntroducedVersion>
<d:Options>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Contacted</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Contacted</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>0</d:Value>
</d:OptionMetadata>
<d:OptionMetadata>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<d:Color i:nil="true"/>
<d:Description>
<b:LocalizedLabels/>
<b:UserLocalizedLabel i:nil="true"/>
</d:Description>
<d:IsManaged>true</d:IsManaged>
<d:Label>
<b:LocalizedLabels>
<b:LocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Not Contacted</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:LocalizedLabel>
</b:LocalizedLabels>
<b:UserLocalizedLabel>
<d:MetadataId i:nil="true"/>
<d:HasChanged i:nil="true"/>
<b:IsManaged>true</b:IsManaged>
<b:Label>Not Contacted</b:Label>
<b:LanguageCode>1033</b:LanguageCode>
</b:UserLocalizedLabel>
</d:Label>
<d:Value>1</d:Value>
</d:OptionMetadata>
</d:Options>
</d:OptionSetMetadataBase>
</c:value>
</b:KeyValuePairOfstringanyType>
</b:Results>
</ExecuteResult>
</ExecuteResponse>

如何解决此错误?

最佳答案

改用 DataContractSerializer - 它会完成这项工作。它可以序列化未标记为 [DataContract][Serializable] 属性的类型(需要默认构造函数 + 只有公共(public)成员将被序列化):

public static string Serialize(this IExtensibleDataObject obj, bool indent = false)
{
DataContractSerializer contractSerializer = new DataContractSerializer(obj.GetType());
using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
{
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
{
if (indent)
{
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.Indentation = 2;
}
contractSerializer.WriteObject(xmlTextWriter, obj);
return stringWriter.ToString();
}
}
}

关于c# - 序列化通过 SOAP 发送的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38042193/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com