Use Windows Form Controls in IE Browser (2)

xiaoxiao2021-03-06  105

Access to Windows Form Control

Web service

An important advantage of form controls is that you can realize rich user information through it on the client. For example, you can access the web service through the Form Control to display in IE without re-refreshing the page. To demonstrate this, let's create a web service, then demonstrate how to call the Web service through the form control.

Create a web service

We created a Visual C # ASP.NET Web Service new project, named AuthorsWebService.

After establishing, we modify the service class name as AuthorsService, add a getauthors method in the class, the code of this method is as follows:

[WebMethod]

Public dataset getauthors ()

{

String connString = system.configuration.configurationSettings.Appsettings ["Connectionstring"];

SqlConnection SQLCONN = New SqlConnection (Conntring);

Dataset Dstauthors = New Dataset ("Authors");

SqlDataAdapter Adapter = New SqldataAdapter ("Select * from authors", SQLCONN);

Adapter.Fill (Dstauthors, "Author");

Sqlconn.close ();

Sqlconn.dispose ();

Return Dstauthi;

}

The code of the above method is relatively simple, we store the database connection string to the AppSettings node of the web.config file, as follows:



Now we need to create a virtual directory to make the control work normally and put authorsdisplay.htm and AuthorsWebServiceClientControl.dll. Open the browser to enter the address, you will see a button and an empty DataGrid, if you click the command button, the control will call the Web service while writing the result in the dataGrid. The page is shown below. In the next section, we look at the debugging of the process.

转载请注明原文地址:https://www.9cbs.com/read-124920.html

New Post(0)