ELSE
* 未找到客户。向调用程序返回 -1。
lyCredLimit = -1
ENDIF
RETURN lyCredLimit
ENDFUNC
ENDDEFINE
示例 3:访问 Visual FoxPro 7.0 XML Web Service
可以使用 ASP.NET 调用通过 Visual FoxPro 7.0 创建的 Web service。
FoxCentral.net (http://foxcentral.net) 是一个免费的 Web 站点,提供 FoxPro 社区感兴趣的信息。此 Web 站点是使用 Visual FoxPro 7.0 创建的,可以用作 Web service,其功能在 XML Web Services 说明语言 (WSDL) 文件中进行了说明,该文件位于 http://www.foxcentral.net/foxcentral.wsdl。
该 Web service 提供了一个 GetItems() 方法,可以调用该方法以返回符合各种标准(作为参数传递给该方法)的张贴项。在 WSDL 文件中,为 Getitems() 方法指定的参数如下:
下面的屏幕快照显示了 Design(设计)视图中显示的 FoxCentral Extract Web 页 (FoxCentral.aspx ) 的 ASPx 文件。其中使用了四个控件,包括两个 Label、一个日历控件和一个 DataGrid。
下面列出了使用 C# 编写的本示例的实现代码。
// 设置对类库的引用。类似于 Visual FoxPro 7.0 中的
SET CLASSLIB TO。
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
// 设置对 Visual FoxCentral.net Web Service 对象的引用。
using FoxCentralASPX.net.foxcentral.www;
namespace FoxCentralASPX
{
///
/// WebForm1 的摘要说明。
///
// 创建 ASP.NET 页对象。
public class WebForm1 : System.Web.UI.Page
{
// 设置对 ASP.NET 页上的服务器控件的引用。
protected System.Web.UI.WebControls.DataGrid dgrNews;
protected System.Web.UI.WebControls.Calendar calDate;
protected System.Web.UI.HtmlControls.HtmlGenericControl cTitle;
protected System.Web.UI.WebControls.Label outError;
// 此方法是由 Visual Studio .NET 生成的。
public WebForm1()
{
Page.Init += new System.EventHandler(Page_Init);
}
// 首次加载 ASP.NET 页以及每次刷新该页时都会运行
Page_Load 事件。
private void Page_Load(object sender, System.EventArgs e)
{
// 此处放置用于初始化该页的用户代码。
// 初始化变量以存储对 FoxCentral.net Web Service
的引用。
foxcentral loData = new foxcentral();
// 初始化要在此方法中使用的其他对象。
string lcXML = "";
string lcError = "";
System.Data.DataSet oDS = new DataSet();
bool lbError = false;
// 将 ASP.NET 页可视属性上的服务器控件
标签和 DataGrid 初始化为 False,
以隐藏这些对象。
outError.Text = "";
outError.Visible = false;
dgrNews.Visible = false;
// 如果是第一次呈现该页。
if (Page.IsPostBack == false)
{
// 将选定日期设置为今天的日期。
calDate.SelectedDate=System.DateTime.Today;
}
try
{
// 调用 FoxCentral.net 的 GetItems 方法,传递用户
输入的日期。
lcXML = loData.GetItems(calDate.SelectedDate,0,0,"ALL");
// 如果未返回数据,将引发异常。
if (lcXML == "")
{
throw new Exception();
}
}
catch(Exception ex)
{
// 如果发生异常,则在 ASP.NET 页上设置错误标签文本
并显示该文本。
lcError = "没有要检索的消息项";
outError.Text = lcError;
outError.Visible = true;
return;
}
try
{
// 将 XML 读入 DataSet。
oDS.ReadXml(new StringReader(lcXML));
}
catch(Exception ex)
{
// 如果发生异常,则获取对错误的引用并将 error 变量
设置为 True。
lcError = ex.ToString();
lbError = true;
}
// 如果发生错误,则在 ASP.NET 页上设置错误标签文本
并显示该文本。
if (lbError)
{
outError.Text = lcError;
outError.Visible = true;
return;
}
// 将 DataView 对象设置为使用 XML
创建的名为“News”的表。
DataView oDataView = new DataView(oDS.Tables["News"]);
// 将 DataGrid 源设置为 DataView。
dgrNews.DataSource = oDataView;
// 绑定 DataGrid。
dgrNews.DataBind();
// 显示 DataGrid。
dgrNews.Visible = true;






