■22954 / inTopicNo.16) |
Re[15]: クラス名を変更するとDeserialize()でエラーが発生 |
□投稿者/ セラナ太郎 (13回)-(2008/08/06(Wed) 11:40:33)
|
////////Webサービス具象クラス//////// namespace ando { public class WebServiceJSC : REST24Ando { [WebMethod] public ando1.ekidata getEkiDataListTodohuken(string strParam) { initXMLObject(new ando1.ekidata()); return (ando1.ekidata)sendRequestCore("http://www.ekidata.jp/api/p/23.xml", "", STR_ENC_UTF8, ""); }
[WebMethod] public ando.ekidata513 getEkiDataListRosen(string strParam) { initXMLObject(new ando.ekidata513()); return (ando.ekidata513)sendRequestCore("http://www.ekidata.jp/api/l/11302.xml", "", STR_ENC_UTF8, ""); } } }
//////Webサービス抽象クラス//////// namespace ando { /// <summary> /// Summary description for REST /// </summary> [WebService(Namespace = "http://wsjsc.com/rest/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] abstract public class REST24Ando : System.Web.Services.WebService { WebResponse _respsWeb; Stream _strmHttp; XMLBaseAndo _objXML;
public const string STR_ENC_UTF8 = "UTF-8"; public const string STR_ENC_SJIS = "S-JIS"; public const string STR_Q = "?"; public const string STR_QQ = "??";
protected void initXMLObject(XMLBaseAndo objXMLnew) { _objXML = _objXMLnew; }
protected XMLBaseAndo sendRequestCore(string strURL, string strParam, string strEncoding, string strOption) { if (0 == strURL.Length) return null; if (0 == strEncoding.Length) strEncoding = STR_ENC_UTF8;
string strMessageREST = strURL + STR_Q + strParam;
while (strMessageREST.Contains(STR_QQ)) strMessageREST = strMessageREST.Replace(STR_QQ, STR_Q); ;
Encoding enc = Encoding.GetEncoding(strEncoding); WebRequest reqWeb = WebRequest.Create(strMessageREST); // リクエストの作成
_respsWeb = reqWeb.GetResponse(); // 送信とレスポンスの取得 _strmHttp = _respsWeb.GetResponseStream();
XmlReader readerXML = XmlReader.Create(_strmHttp);
XmlSerializer serializerXML = new XmlSerializer(_objXML.GetType());
_objXML = (XMLBaseAndo)serializerXML.Deserialize(readerXML); readerXML.Close(); _strmHttp.Close();
return (XMLBaseAndo)_objXML; } } }
------------------------------------------------------ //////// シリアライズドXML クラスの抽象クラス //////// abstract public class XMLBaseAndo : Attribute { }
////////路線 シリアライズドXML クラス//////// ////マスターXML http://www.ekidata.jp/api/l/11302.xml 戻り値//// namespace ando //+*+* 追加 { using System.Xml.Serialization;
/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] [XmlRoot(Namespace = "", ElementName = "ekidata", IsNullable = false)] //+*+* ElementName追加 public partial class ekidata513 : XMLBaseAndo //+*+* 修正 ekidata -> ekidata513 XMLBaseAndoから継承 { private string station_cdField; private string station_g_cdField; private string station_nameField; private string lonField; private string latField; }
/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = false)] [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.ekidata89.jp/", ElementName = "ekidata", IsNullable = false)] public partial class NewDataSet513 : XMLBaseAndo //+*+* 修正 NewDataSet -> NewDataSet513 XMLBaseAndoから継承 { private ekidata513[] itemsField;
/// <remarks/> // [System.Xml.Serialization.XmlElementAttribute("ekidata")] //+*+*削除 public ekidata513[] Items { } } } ------------------------------------------------------ ////////都道府県 シリアライズドXML クラス//////// ////マスターXML http://www.ekidata.jp/api/p/23.xml 戻り値//// namespace ando1 //+*+* 追加 { using System.Xml.Serialization;
/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] // [XmlRoot(Namespace = "", ElementName = "ekidata", IsNullable = true)] //+*+* 一行追加後 コメント化 //key:aa333 public partial class ekidata : XMLBaseAndo //+*+* 変更 XMLBaseAndoから継承 { private ekidataPref[] prefField; private ekidataLine[] lineField; private string versionField;
//以下get/set 関数削除 }
/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] public partial class ekidataPref { private string codeField; private string nameField; //以下get/set 関数削除 }
/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] public partial class ekidataLine { private string line_cdField; private string line_nameField;
//以下get/set 関数削除 }
/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] [System.Xml.Serialization.XmlRootAttribute(Namespace = "", ElementName = "ekidata", IsNullable = false)] //+*+* ElementName追加 public partial class NewDataSet : XMLBaseAndo { private ekidata[] itemsField;
/// <remarks/> // [System.Xml.Serialization.XmlElementAttribute("ekidata")] //+*+*削除 public ekidata[] Items { } } }
|
|