我正试图以增量方式将遗留应用程序引入当前技术。我有一个C++COM+库,在服务器上使用ADO。VB6应用程序正在使用基于上述库的COM+对象的记录集。我想删除COM+层,所以我用ASP创建了一个ReST web服务。NET Web API项目类型。使用C#中内置的HTTP结果(即Ok和BadRequest),我似乎无法像返回其他数据类型那样返回记录集。我一直试图通过记录集持久性来实现这一点。我将记录集保存为流,如下所示:
ADODB._Recordset rs;
string rsString;
SomeLibrary sl = new SomeLibrary();
rs = (ADODB._Recordset)sl.SomeMethod();
Stream stream = new Stream();
rs.Save(stream, PersistFormatEnum.adPersistXML);
rs.Close();
rsString = stream.ReadText();
return Ok(rsString);
C#客户端尝试获取这个持久化的ADO记录集并重新创建对象,如下所示:
_Recordset ret = null;
string strResponse = string.Empty;
Does things to call out to the ReST web service...
ret = new Recordset();
byte[] rsByteArray = Encoding.ASCII.GetBytes(strResponse);
ret.Open(new MemoryStream(rsByteArray));
参数类型错误、超出可接受范围或相互冲突。
持久化的XML如下所示:
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly' rs:CommandTimeout='600' rs:ReshapeName='DSRowset1'>
<s:AttributeType name='ID' rs:number='1'>
<s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/>
</s:AttributeType>
<s:AttributeType name='c1' rs:name='Some Date' rs:number='2' rs:nullable='true'>
<s:datatype dt:type='dateTime' rs:dbtype='timestamp' dt:maxLength='16' rs:scale='3' rs:precision='23' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='Status' rs:number='3' rs:nullable='true'>
<s:datatype dt:type='ui1' dt:maxLength='1' rs:precision='3' rs:fixedlength='true'/>
</s:AttributeType>
<s:AttributeType name='c3' rs:name='File Name' rs:number='4' rs:nullable='true'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='2000'/>
</s:AttributeType>
<s:AttributeType name='c4' rs:name='User ID' rs:number='5'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='32' rs:maybenull='false'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ID='3319' c1='2017-06-26T08:14:46' Status='2'
c3='somefile.XML' c4='domain\\user'/>
</rs:data>
</xml>
目标是将ADO记录集发送回VB6应用程序,这样它就永远不会知道实现发生了变化,除了可能对新C#库而不是COM+库的新引用之外。
我写的东西中是否有bug,或者这是不可能的?如果不可能,有人知道我可以采取不同的方式来完成这项任务吗?
编辑:
ADODB.Stream stream = new ADODB.Stream();
rs.Save(stream, PersistFormatEnum.adPersistXML);
rs.Close();
rsString = stream.ReadText();
return Ok(rsString);
和客户:
_Recordset ret = null;
string strResponse = string.Empty;
Does things to call out to the ReST web service...
if (!string.IsNullOrEmpty(strResponse))
{
strResponse = strResponse.Replace("\\t", " ").Replace("\\r\\n", " ").Replace("\"", "");
ret = new Recordset();
ADODB.Stream stream = new ADODB.Stream();
stream.Open();
stream.WriteText(strResponse);
stream.Position = 0;
ret.Open(stream);
}
return ret;
VB6模块现在可以接受数据,就像它从COM+对象接收数据一样。我希望这能帮助其他需要廉价更新技术的人。