Question about Web service calling methods

Source: Internet
Author: User

According to the customer's requirements, the new project should adopt the Smart Client architecture. If the client and the server are used.. net. if remoting and WCF are all java (server-side SSH, client Swing), you can consider using JMS. However, after discussing with the company's technical director, to use server-side java (SSH + Xfire), client C # + WinForm framework, Web Service is required for communication between the client and the server.

There are two ways to achieve communication between the client and the server:

1. Multiple Web Service interfaces are used, that is, one application layer object corresponds to one Web Service interface, and one application layer method corresponds to one Web Service method, parameters and return values are simple objects (such as VO) based on business needs, such as Book BookStore. addBook (Book book );

2. All externally published application-layer services adopt a unified Web Service interface, that is, a message layer is added to the application layer. This layer has only one Web Service Interface, for example: string sendMsg (String msgCode, String xmlDoc), in the message layer, according to The msgCode sent from the client, assemble the content in xmlDoc into VO according to the system's definition of each node label (for example, pre-defined <book> label and Its subnodes), and then select the appropriate service layer method call, the returned message is also closed to XML and returned to the client for resolution and subsequent processing. For the addBook method above, you can define a msgCode = "addBook" to serialize the Book object in xmlDoc, such as <book> <bookname> Java Programming classic </bookname> <author> John </author> </book>.

The first method is more formal. The same API can be used for calls within the application server container and cross-platform remote calls, which is easier for developers to use and understand. However, communication between different languages and different web service implementation frameworks is not very convenient (the degree of rigor following web service specifications is not too uniform), and complicated objects may encounter errors during parsing. Especially when passing object arrays and List objects, it may be a bit difficult to implement the old and eccentric languages and Web services.

The second method is actually a degradation of Web Services. Soap is discarded, but the name of a Web Service is suspended, the Web Service is actually used as a string communication protocol. On the server side, a message processing layer is added to this method. The judgment of the message code to the interface method at the application layer and the conversion of XML documents to VO are required, it will reduce the processing efficiency and be prone to errors (of course, you can write a general method for processing ). But its strength lies in its convenience and simplicity. On the one hand, it only needs to provide an interface method senmsg () to the client Programmer (inside the company or a third-party company () that's all. A list of message codes for various application-layer service methods and a message body in XML format can be used. The client programmer does not need to have a very "heavy" web
The service implementation framework can access the server. On the other hand, the two sides only need to implement the Web service that can pass strings, so as to avoid the problem of complicated document formats and parsing errors, that is, the compatibility is good. Security Authentication, encryption, and tamper-proofing can also be achieved directly from strings without complicated and heavy web service security mechanisms, so you don't have to worry about it. You can also go straight to SSL.

Another advantage of the second method is that you do not need to frequently publish Web service interfaces. it is costly to implement an interface on the client. Well done, encapsulated, all client developers can use it directly, but the message parameters are different. For the xmldoc parameter, you can take some time to make a good tool method and convert the VO of C # To xmldoc through reflection.

For Web service interfaces, the Access frequency and access volume restrictions are very important, for fear of "refreshing" the client! Specify a client in one minute (using an IP address? Is there a gateway, or is it determined by the Client ID or user ID ?) The number of visits, and the total number of visits within one day. The access conditions should be stored in the system log database of the server or in the session, and the judgment and processing should be performed at the message layer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.