19Web service

Web Service


Web Service

Micosoft.Net platform architecture in a distributed system consists of two parts: building server-side dynamic web pages, and Web services (Web Service or XML Web Service) with ASP.Net technology. The front section has been introduced method for building server-side dynamic web pages of detailed, chapter introduces the basic concepts of Web services and construction method.

13.1 Web concept and use of services

Web pages in either static or dynamic pages, data is embedded in Web pages, Web service objects are people, users can easily read these pages. But if a program uses the data obtained in this way, it will be very difficult, the program must be separated from the data page, it can be used. Obtained using a Web program in the data sometimes is necessary, for example: a meteorological station want to get a variety of information through various grassroots observatory of Internet, released a unified web page on the Internet. Meteorological Station Meteorological hope that all the grassroots to provide an Internet service that can automatically provide the appropriate information as required terminus. Similar examples are many, such as information systems integration between headquarters and subordinate units of a large unit, a comprehensive website want to automatically obtain information provided by other sites and so on. This demand is actually a Web service.

To achieve this functionality there are many difficulties, various grassroots observatory system used may be completely different, even if the same operating system, or it may use a different database systems, field defined in the database may be different, database application might use different language preparation , even if these are identical, but also may indicate how the data is not the same, such as data format, data bits and so on. To solve these problems, many solutions have been proposed, such as: Microsoft Distributed control object model (DCOM), the Object Management Group's (OMG) Common Object Request Broker Architecture (CORBA), SUN's Remote Method Invocation (RMI ), etc., but these methods can not solve the above problems.

Micosoft.Net Web services to achieve this function provides a complete solution. Web services using XML description data assurance procedures will be appreciated that transactions; the SOAP protocol XML data package as a message, SOAP (Simple Object Access Protocol, Simple Object Access Protocol) is an XML-based messaging protocol, because it is based on XML, to ensure that the among different programs of different systems, as long as the SOAP support, can communicate with each other; SOAP messages transmitted over the Internet using Http protocol. Web services implemented Micosoft.Net meteorological station probably thinking required function is such that each primary meteorological provide a remote Internet calling functions in their systems, the function to accept the call represented by SOAP with HTTP protocol, and the the return value of the function with the XML extensible markup language to describe, said after using SOAP, returned to the caller using the HTTP protocol. Meteorological Station as long as the use of HTTP and SOAP protocol to call these one by one Web Remote function, you can get information on the various grassroots observatory returned in XML representation, the program is easy to analyze data represented in XML extraction. Since the agreement These agreements are widely accepted in different systems, XML data can be understood by different systems of different programs, it would resolve the problems set forth above.

From the above description, Web services, not the pursuit of portability of the code, but to provide a viable solution to enable data communication and understanding between different systems program. There are many Web service definition, relatively simple and easy to understand description: Web services is a system independent, Web remote library can be accessed via HTTP, SOAP and XML protocols.

Just the issues discussed are just a few applications of Web services, there are many other uses, such as:

Application Integration

You can use Web services in an integrated manner on the surface appear to integrate disparate existing applications. For example, each department many companies have custom software that generates a series of useful but isolated data and business logic. For the convenience of management, it is necessary to the collection of these applications function together. Using Web services, it is possible the data and functionality of existing applications as a Web service provided to other sectors. You can then create an integrated application, enhancing interoperability between various departments.

code reuse

In the software development industry, most software developers are dependent on code reuse. Over the past software developers to take advantage of the code that others have achieved, or copy the snippet to your code, make some changes to accommodate that she has needed, or install a database on a server or a personal computer, allowing the application to access the library . This will make the code there are many versions, but may be subtle differences between these versions, but scattered in various places. When the code was originally the developers decided to look at the code update or correct some mistakes, I should tell all these changes when using this code developers will be very difficult. If we put code in a central storage location for all to visit here, this is not good? After this the creators can do some additions or amendments, can be immediately available to all who use it. Can be achieved using Web services envisaged above, the method of remote Web service calls, as calling a local function as convenient.

workflow solutions

Some of the work is very complex, such as transportation of goods, you may want to use a variety of vehicles, trains, cars, ships, etc., it is a very complex process, every step of the process by the different programs in different sectors of control, how to build links between these control procedures, it is very important. Web services is a good solution. Web services, so that each flow control procedures to establish contact, fully automatic control and management of freight transport.

new sales

Sales of software user is now generally buy back the software installed in your computer. With Web services, you can use the software to provide services, remote users can use the application software, pay per view.

by the Web automation system consisting of service

The near future, information appliances will be coupled onto the Internet, PDA, cell phone, or even a variety of embedded devices have Internet access, between these devices and other devices to establish contact is also a viable option through Web services.

13.2 build Web services

Web services are still using client / server (Client / Server). This section describes the server side should do the work, including the establishment of a method for Web service client calls, and WSDL document to the client using the Web service method, provided to the client describes the Web service.

13.2.1 Use Notepad to build Web services

Examples e13_2_1A : build a Web service file and build a common web document step is basically the same, below is a simple Web service file, other programs access to one of the Web service method, it will return parameters a and b and the specific program code show as below:

<%@ WebService Language="C#" class="MyClass"%>

using System;

using System.Web.Services;

public class MyClass:WebService

{     [WebMethod]

public int MyWebMethod (int a, int b) // note parameter name will appear in the FIG 13.2.1C

{     return a+b;

}

// Other WebMethod 

}

In the document, the first line of the statement indicates that this is a Web service file, using the C # language, the name of the Web service class is MyClass. Article 4 statement creates a derived class MyClass WebService class to the base class, the class must be a public class. Web service classes WebService class does not have to establish a base class, but WebService class is derived, obtained access to the ASP.Net objects (such as Application and Session) are. The base class to class WebService namespace must be introduced System.Web.Services. Other methods are available to access the Internet called Web service method, you must increase the keyword [WebMethod] at its head, indicating that the method is a Web service method, this method must be a public method.

After the establishment of the file to save asmx extension, saved to the host site's directory or any subdirectories, WriteBook directory e13_2_1.asmx present embodiment to keep the host site directory. Now use the browser to test the Web service method, using the URL locate the Web service method, enter the following address in your browser's URL address field: http: // localhost / WriteBook / e13_2_1.asmx, the browser displays Figure 13.2. 1A.

                       

Figure 13.2.1A

You can see the page suggestions: "This Web service using http://tempuri.org/ as its default namespace suggestion: in public before the XML Web service, change the default namespace." These words mean to distinguish and other Web services, when you publish a Web service must have a unique namespace, you can use the URL or IP address of your organization as this namespace. Modify e13_3_1A.asmx to e13_3_1.asmx as follows:

<%@ WebService Language="C#" class="MyClass"%>

using System;

using System.Web.Services;

[WebService(Namespace="http://202.206.96.204/")]

public class MyClass:WebService

{  [WebMethod]

   public int MyWebMethod (int a,int b)

   {    return a+b;

   }

   // Other WebMethod 

}

       Once again, use the URL http: //localhost/e13_2_1.asmx run, it will not appear recommendation section, as shown in 13.2.1B.

 

Figure 13.2.1B

Click MyWebMethod, like Figure 13.2.1C browser.

 

Figure 13.2.1C

Two addend input in the edit box, respectively, 10 and 20, and then click on the "call" button, open another browser window is shown 13.2.1D, this is the result of calling the Web service method as an XML tag MyWebMethod returned. Please note that this is just a test run, in fact, should generate a Web service client program calls on other computers, can be a Windows application that can also be a console application or ASP.Net application, that is, can be Micosoft.Net system program, the system may also be other programs, such as Java programs, Linux programs, etc., under section describes this knowledge.

 

Figure 13.2.1D

13.2.2 build Web services with VS.Net

If you use this Web service VS.Net build file, follow these steps:

(1) New asp.Net web services, type in "position (L)" edit box: http: // localhost / e13_2_2, which is the name e13_2_2 project. Click the "OK" button to create the project.

(2) you can see the title "Service1.asmx.cs (Design)" window. Right-click the file in the pop-up shortcut menu, click "View Code (C)" menu item, open source file Service1.asmx.cs Figure 13.2.2.

 

Figure 13.2.2

(3) does not occur in order to access the advice presentation, add the following statement front Service1 class definition: [WebService (Namespace = "http://202.206.96.204/")].

(4) file has a Web service method HelloWorld, but commented out. Add the following Web service method MyWebMethod as follows:

[WebMethod]

public int MyWebMethod(int a,int b)

{     return a+b;

}

(5) Now test the Web service with the IE browser, press F5 to run the show (different class name) interface similar to Figure 13.2.1B, click on MyWebMethod, the browser displays as shown 13.2.1C. Two addend input in the edit box, respectively, 10 and 20, and then click on the "call" button, open another browser window is shown 13.2.1D, this is the result of calling the Web service method represented in XML MyWebMethod returned.

13.2.3 Services Description Language (WSDL)

Web services provide a service that allows computers on the Internet using HTTP and SOAP Web services protocol for remote method invocation. We all know that in order to use a function, first of all look at the instructions function. Web service method also has the same problem, especially SOAP protocol, which uses XML markup language messaging Web services, and XML markup language that can define your own tags, but does not provide a general SOAP XML tags for Web services use different Web XML tag definitions services SOAP may be different. Accordingly, in order to make calls to other systems of different Web services in the system must be made a detailed description of the format and method of invoking the Web service of the Web service returns a service description data, and this description should be widely accepted protocol.

WSDL (Web Services Description Language) Chinese name for the Web Services Description Language for Web service description. WSDL is an XML-based, generating WSDL an XML document, may provide operational information about the Web service, for example, an abstract form of service interface information, specific access protocol and format of data transmission, for clients to use the details of the Web service, and the like Wait. Service description WSDL is an XML document using the language, can understand the definition of a Web service Web service message format. Services acts as a description of the agreement to define the behavior of a Web service and instructs how to interact with potential customers. WSDL document the most important use is to generate a proxy class on the client side, as detailed in section 13.3.3.

Since it is possible to automatically generate the WSDL document in VS.Net, the WSDL is not presented here. You can see by the following method to automatically generate the WSDL document VS.Net, such as viewing a Web service generated the previous section, enter the http in the browser URL address:? // localhost / e13_2_2 / Service1.asmx WSDL, display the browser the Web service WSDL document. Or click on the map 13.2.1B service description can also see the WSDL document.

13.3-based Web service client program in .Net

Web service client program is used to invoke the Web service method on the server side, front to use the browser to call a Web service method can only be counted as one test, this test can verify the correctness of the Web service method, we found an error. As a client, no matter where you are, using the kind of operating system, as long as want to know where the Web service URL, you can invoke the relevant Web service method. Web service client program should generally be in another computer Web online, only do experiments or learning, and Web services can also be on the same computer. This section describes how to implement a Web-based service client program of .Net.

13.3.1 protocol used to invoke the Web service method

The client can be used three protocols call the Web service method: HTTP-GET, HTTP-POST and SOAP protocols. HTTP-GET and HTTP-POST protocol is a standard protocol for Web pages passing parameters. Using the HTTP-GET method e13_2_1.asmx call the Web service of, the following can be entered in the address bar IE browser will return to FIG 13.2.1D web, note a and b are parameter name of the Web service method.

http://localhost/WriteBook/e13_2_1.asmx/MyWebMethod?a=10&b=20

If you use the Web service method call in e13_2_1.asmx HTTP-POST, can be used the following pages:

<html>

  <body>

    <form method="POST" action="e13_2_1.asmx/MyWebMethod">

      The first addend input a: <input name = "a" Value = ""> <br>

      The second addend input b: <input name = "b" Value = ""> <br>

      <Input type = "submit" value = "invoke Web services">

    </form>

  </body>

</html>

Input Notepad this page, note a and b is the parameter name of the Web service method to file e13_3_1.htm file name into e13_2_1.asmx located. Open this page with a browser, the browser displays the results as follows. As shown in Figure two input addends, click the button to call the Web service, will be back to FIG 13.2.1D page.

 

Figure 13.3.1A

Using the HTTP-GET and HTTP-POST protocol to transfer Web page parameter variable name can only be used / variable value pairs can not be delivered as the DataSet, binary files and other types of data, in order to transmit complex data types, SOAP protocol may be employed. SOAP (Simple Object Access Protocol, Simple Object Access Protocol) is an XML-based messaging protocol, because it is based on XML, to ensure that the different programs or between different components of the system, as long as the support for SOAP, can communicate with each other, more SOAP specifications information, see the W3C Web (http://www.w3.org/TR/soap) site. The Web service using SOAP protocol to call the method e13_2_1.asmx necessary and a method for a Web service using SOAP protocol parameter called package, to achieve more complex, .Net system using the general procedure to create the proxy class, and therefore no description SOAP encapsulation method, after section gives a detailed knowledge to create the proxy class.

13.3.2 VS.Net build Web service client program

Web service client calls the remote Web service method using SOAP protocol, Web service client program must call the program and its parameters into SOAP protocol, sent to the Web service. After calling the Web service method, the Web service method returns results in XML, we also need to parse XML documents to obtain a specified type of data. These work more complicated. Programmers looking to adopt common programming languages ​​like calling a method that calls a Web service method, return the specified type of data. .Net system uses a method to create a proxy class for this purpose. The so-called proxy is generated locally on the client objects, as a front-end remote Web service method, the agent functions, Web service client invokes a Web service method with general programming language as the agent responsible for converting the SOAP protocol with SOAP the agreement calls a Web service method, the agent responsible for obtaining the data returned by the Web service method, since these data are also represented by SOPA agreement, but also by the agent for the conversion of data types can understand the general programming languages, transmitted to the Web service client program .

VS.Net tool provides a way to create a Web service proxy class in the client, the client program and Web services need not necessarily on the same computer, you can Renyiyitai Internet computer network. The client program can be windows applications, ASP applications that can be another Web service program. Below to create a windows application as an example, describes how to create a proxy class in the Web service client, follow these steps:

(1) Open VS.Net, the new C # language windows application project, project life is e13_3_2, add a button to the form, titled "Calling Web Services," click the button to call the Web service Web method, and in the window 2 increase body text box for inputting the two addends. 3 as a control message Label, Text attributes are: addend a, addend B, and. Showing results returned after calling a Web service Web method using a Label control. FIG design interface 13.3.2D.

(2) establish a Web service client proxy. Click VS.Net menu "Project" | "Add Web Reference" menu item, the pop-up titled "Add Web Reference" dialog box shown in Figure 13.3.2A.

 

                                                     Figure 13.3.2A

(3) In the dialog box "address (A)" field, enter the URL Web services, Web services should generally be in the remote computer. This example Web services and clients on the same computer that is used in section 13.2.2 VS.Net build a Web service, the URL is http: //localhost/e13_2_2/Service1.asmx. You can not use the example e13_2_1 build Web services, because it can not automatically create a WSDL file. Then click the "Address (A)" arrow icon in the right column, V S.Net automatically finds the specified URL of the WSDL file. Figure 13.3.2B.

 

Figure 13.3.2B

(4) Click the title to "Add Reference" button in Solution Explorer, you can see a new "Web References". Figure 13.3.2C. Reference Service1 following format: localhost.Service1.

(5) as a function button to increase the event as follows. Note Service1 method reference.

private void button1_Click(object sender, System.EventArgs e)

{ int x,y;

x=Convert.ToInt16(textBox1.Text);

y=Convert.ToInt16(textBox2.Text);

localhost.Service1 ws=

new localhost.Service1();

label4.Text=ws.MyWebMethod(x,y).ToString();

}

(6) Press F5, Run, type 2 addend, click titled "Web service call" button, and display 30.

 

 

 

 

 

 

Figure 13.3.2D Figure 13.3.2C

13.3.3 WSDL program

The .Net Framework SDK provides a command-line program WSDL.EXE, the program can automatically generate a proxy for the Web service client program. Below describes the specific method of generating agent. WSDL.EXE must be used under the console interface, the client proxy class to generate e13_2_2 example of Web services, for example, uses the following format:

wsdl /l:C# /OUT:Service1.cs /protocol:soap http://localhost/e13_2_2/Service1.asmx?WSDL

Wherein, / l to specify the language client program uses the preparation of Web services, may be vb, C #, and Jscript, the default value is C #; / OUT parameter to specify the proxy class files generated in the path and file name, the default value, and Web services ASMX file of the same name, extension, called the language specified parameter l / expansion; parameter / protocol specifies the protocol to call the Web service method, which can be HTTP-GET, HTTP-POST and SOAP protocols; http: // behind ASMX Web services URL of the file. WSDL.exe is a green software that can be copied to any location operation. The results generated WSDL source is running a Web service client proxy class, you can view its source code in Notepad. With the source code, the compiler also generates source dll file format is as follows: csc / t: library Service1.cs, using the method in Section 1.2. Service1.dll ultimately generate a document, you can use it to generate client proxy class.

VS.Net WSDL.EXE also use the client program to increase agent. If you do not use VS.Net, it can only be used directly WSDL.EXE generate client program to increase agent.

Examples e13_3_3: console application calls a Web service method, the source code is as follows:

using System;

using System.Web.Services;

class UseService1

{

public static void Main()

{ string s;

int x,y,z;

Console.WriteLine ( "first addend input a:");

s=Console.ReadLine();

x=Convert.ToInt(s);

Console.WriteLine ( "enter the second addend b:");

s=Console.ReadLine();

y=Convert.ToInt(s);

Service1 ws = new Service1 (); // agent class object

z = ws.MyWebMethod (x, y); // call the Web service method

Console.WriteLine("sum:={0}",z);

}

}

UseService1.cs save the file name, and Service1.dll in the same folder, use the following command to compile the code: csc /r:Service1.dll UseService1.cs, generate UseService1.exe, run the resulting UseService1.exe program, after two addend input, outputting a calculation result on the CRT.

Such as the use Notepad to generate ASP.Net page document calls a Web service, it is necessary to generate the Service1.dll file saved to a subdirectory bin directory of the page file, the proxy class can be used this ASP.Net page. I invite the reader to this example.

13.3.4 synchronous and asynchronous Web services

The above described method the client calls the Web service to Web service method has been waiting for the end of the run, returns the result to perform other procedures, this method is called synchronous mode to call the Web service call. If the Web service method to access a remote database, perform network I / O read and write large files, it will take a lot of time to perform these operations, synchronous Web services model will reduce the efficiency of the program, then you can use asynchronous Web service invocation model. The so-called asynchronous Web service calls after the program execution Web service call, does not wait for the results returned, but the implementation of other programs, hope to get back up to the Web service method returns data only retrieve data analysis. Service1.cs 13.3.3 section generated There are two ways BeginMyWebMethod and EndMyWebMethod is to implement asynchronous invocation of Web services model, the interested reader may refer to the literature in-depth study.

13.3.5 different systems interoperable Web services

The preceding merely introduces the establishment and use of .Net Web services systems, so different systems Web services can interoperate whether it? In other words, if a client system can use another system of Web services? The answer is yes, but the implementation is very troublesome. This is mainly to achieve the various systems of WSDL, details Soap agreements are not exactly the same, the system does not automatically generate a lot of agents, a lot of work must also be implemented by the programmer. Programmers first thing to do is to call the program and its parameters into SOAP protocol, sent to the Web service program with Http-Post protocol. After the Second call a Web service method, the Web service method returns results in XML, we also need to parse XML documents to obtain a specified type of data. Many companies provide a SOAP toolkit to create and analyze SOAP messages. These kits are usually a function call is converted from one language to SOAP messages. For example, Microsoft SOAP Toolkit 2.0 to COM function calls into SOAP, and JAVA Apache Toolkit will function calls into SOAP. Parameter data type and the type of function calls to support implementation of different schemes are different with each SOAP, it is applied to a kit function may not apply to other toolkits. This is not a SOAP limitation, restriction of a specific implementation but used. This course is not introduced this knowledge, the interested reader is referred to the relevant literature, for further study.

13.4 publishing and discovering Web services

Web services should include three roles: Web services provider, Web service caller, Web services registered ICC. The relationship between them in the following figure.

Complete Web services development, Web services Web service provider in order to allow the caller to find their own Web service, the Web service must be registered to the ICC to register their Web services. Web service call to the Web service that only those who registered ICC inquiry to find the Web services they need. Of course, not all Web services applications, including more than three parts, for example, weather, application integration described in the previous section, workflow solutions and other Web service does not require registration, and code reuse, the new sales Web services need to be registered. As a programmer, learning should focus on learning to create Web services server and client programs. This section briefly describes the Web service to publish and find the problem.

 

               Figure 13.4

13.4.1 Web Service Publishing

And any other resources on the Internet, as if there is no method to find, is not able to find a particular Web service. In order to achieve the registration and find Web services, Microsoft, IBM and Ariba cooperation established a Web site with a UDDI (Universal Description, Discovery and Integration, Universal Description Discovery and Integration specification): http: //www.uddi.org/, Web services allows Web service providers publish information they provide on which, and the Web service users can query the required Web services on this site.

UDDI is a platform-independent, open architecture, can describe a Web service, discovery service, and to provide an operational registry that allows Web service providers to register. Now we have hundreds of companies to support UDDI protocol.

13.4.2 Web Service Discovery

Programmers can find the required Web services through the following steps:

(1) First, visit the Web service URL directory, for example http://www.uddi.org/, find the Web service will return a desired Web service URL.

(2) in accordance with the return URL, visit this Web site using the following format: Web service returns the URL // discro: http?. disco file is an XML file to connect to other descriptive XML Web service that contains resources. .Net Web services to automatically create the XML Web service disco file, the reader can be used the following words to access web services example e13_2_2 the disco file: http:? //Localhost/e13_2_2/Service1.asmx disco.

(3) using Web services to create a WSDL Web service client proxy class.

(4) establish a Web service client program that uses a proxy class to access the Web service method.

Examples 13.5 Using Web services

This section describes two practical examples of the use of Web services, further information on the use of Web services.

13.5.1 .Net Web services support system data types

Not all data types can be used as a Web service method parameters and return values ​​of data types, because a data type in different systems, the definition of the format may be different, for example, a common type int, the number of bits in different systems It may be inconsistent. To solve this problem, XML Schema Definition draft specifies the data type and the definition of Web services should be supported. Include basic types: String, Char, Boolen, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, Decimal and the like, as well as class, struct, DataSet, XmlNode, String [], DataSet [], XmlNode [] and many more. Web .Net system service support above data types.

13.5.2 Using the Web service returns database table

Using Web services, often to query the database in the specified data, the general data for a database table. Because Web services are not supported or DataTable class object and return value data types, it is necessary to DataSet DataTable class object into object classes, data type as the return value, below is an implementation example.

Examples e13_5_2A: This example creates a Web server program that the Web service method returns the database StudentI Chapter 8 created the Student table. Use of this Web service VS.Net establish specific steps are as follows:

(1) create asp.Net web service project, the project is named e13_5_2.

(2) in accordance with paragraph (4) Examples section e8_12 8.12 in the step (8) created in step OleDbConnection object, OleDbDataAdapter objects and data objects in a DataSet.

(3) an increase in the constructor Service1 statement is as follows:

dataSet11.Clear();

oleDbDataAdapter1.Fill(dataSet11);

(4) does not occur in order to access the advice presentation, add the following statement front Service1 class definition: [WebService (Namespace = "http://202.206.96.204/")].

(5) adding a Web service method MyWebMethod as follows:

[WebMethod]

public DataSet MyWebMethod ()

{     return dataSet11;

}

Examples e13_5_2B : This example creates a Web service client program, click the button, call the example Web service method e13_5_2, will use the database StudentI return in the Student table is displayed in the DataGrid control. Specific steps to create Windows applications using VS.Net as follows:

(1) Open VS.Net, a new Windows Application project, project life is e13_5_2B, add a button to the form, titled "Calling Web Services," click the button to call the Web service method of example e13_5_2. Add a DataGrid control that displays the database StudentI return after calling the Web service method in the Student table.

(2) Add the Web according to a reference example e13_3_2 method.

(3) increase event for the button function as follows:

private void button1_Click(object sender, System.EventArgs e)

{   localhost.Service1 ws=new localhost.Service1();

DataSet ds=ws.MyWebMethod();

dataGrid1.DataSource=ds.Tables[0].DefaultView;

}

(4) compile and run, click on the title to "call the Web service" button, the database StudentI in the Student table in a DataGrid control.

13.5.3 Web services transfer graphics files

This section describes the method of service delivery graphic files using Web. The basic idea is to convert the graphic file server into a byte array, is transmitted to the client, and then converted to a graphic file and displays the following steps:

Examples e13_5_3 : in the Web server service method as follows:

[WebMethod]

public byte[] GetImage()

{   string s=Server.MapPath("p1.GIF");

    if(File.Exists(s))

    {   FileStream fs=File.OpenRead(s);

        int n;

        MemoryStream fst=new MemoryStream();

        while((n=fs.ReadByte())!=-1)

        {  fst.WriteByte(((byte)n));

        }

        fs.Close();

        return fst.ToArray();

    }

    else

    {   return new byte[0];

    }

}

Example sub e13_5_3B: Building a Windows client application, add a Web reference in accordance with the example e13_3_2 methods. Add a button titled "Calling Web Services", add a PictureBox control is used to display graphics files transfer. Button click event function is as follows:

private void button1_Click(object sender, System.EventArgs e)

{   localhost.Service1 ws=new localhost.Service1();

    byte[] B1=ws.GetImage();

    MemoryStream fst=new MemoryStream(B1,0,B1.Length);

    Bitmap image=new Bitmap(fst);

    pictureBox1.Image=image;

}

exercise

(1) Please tell other examples of the use of Web services.

(2) modify the example e13_3_2 for the ASP.Net application, this time, the website provides an interface that allows users to access this page two addend input, click the Calculate button, call the Web service method on another computer calculation and two addend. At this time should generate proxy classes on computer web page is located. (Tip: To be completed in two computers)

(3) modify the example e13_3_2, the client program is a Web service, the Web service method call summing e13_2_2 example of, how to achieve. (Tip: To be completed in two computers)

(4) In Web services, and you can also use the Application Session object, using the same method and ASP.Net. Modify example e15_5_2, the DataSet object into the Application, the use of Web services for all.

(5) Modified Example e15_5_2, the client program to provide a Sql statement, Web service method queries the specified data in accordance with this Sql statement, returned to the client.

(6) to complete the example e13_5_3. (Tip: use namespace file must be introduced using System.IO;)

(7) Examples e13_5_3 read documents that can go wrong, how to deal with.

Guess you like

Origin www.cnblogs.com/Aha-Best/p/10931787.html