xmlファイルをオブジェクト型に変換し、そのオブジェクトをWebサービスに渡す必要があります。 サンプルxmlをPFBします。XMLファイルをオブジェクト型に変換する際の問題
はdeserialize
このXMLながら、私は以下の例外を取得しています。
**`System.InvalidOperationException**`
Additional information: There was an error generating the XML document.
Message: The type `CallingWebserviceTest.Claims` was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
サンプルコードは:
XmlDocument doc = new XmlDocument();
doc.Load(Path)
StringWriter sw = new StringWriter();
XmlTextWriter tx = new XmlTextWriter(sw);
doc.WriteTo(tx);
Claims c = new Claims();
StringReader strReader = new StringReader(sw.ToString());
XmlSerializer serializer = new XmlSerializer(typeof(Claims));
XmlTextReader xmlReader = new XmlTextReader(strReader);
c = (Claims) serializer.Deserialize(xmlReader);
私も例外を処理するために、XmlIncludeを追加しましたが、その後も、それを取得しています。クレームクラスの
サンプルコード:
[XmlInclude(typeof(CallingWebserviceTest.Claims))]
[Serializable]
//[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class Claims
{
---
}
[XmlInclude(typeof(CallingWebserviceTest.ClaimsClaim))]
[Serializable]
//[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public class ClaimsClaim
{
---
---
}
誰も私がこの問題を解決する助けてくださいことはできますか? xmlをオブジェクト型に変換するための他の提案も歓迎します。
を使用していますか?このようなもの: 'public class ClaimsClaim:Claims' – Nino
[mcve]を提供し、あなたのXMLを画像ではなく*テキスト*として含めます。あなたはあなたが提供したもので問題を再現することはできません([this fiddle](https://dotnetfiddle.net/Zguf7E)参照)。 XMLの生成中にエラーが発生したように見えるため、関連性がないようです。 –