Server-side thinking, server-side thinking
Overview
We think about what a web Service needs to do and divide its responsibilities. Division of duties Usually we will first develop Abstract
InterfaceAnd then construct
Implementation class. Interfaces and implementation classes are completed before implementation.
Release. Therefore, server roles can be divided:
Service Interface,
Service implementation,
Service publisher. Server implementation Merit Yes : Set A Pull Bo Quantity Word Transfer Change Cheng Medium Text Quantity Word Collation Column . Service Interface
Package cn. ljl. sand. jws. chapter1.service; import javax. jws. webParam; import javax. jws. webResult; import javax. jws. webService; @ WebServicepublic interface InterpretService {@ WebResult (name = "chnum") // The name Of The default result is return public String interpret (@ WebParam (name = "num ") /* the default parameter name is arg0, arg1... */int num );}
Note:
Service implementation class
Package cn. ljl. sand. jws. chapter1.service; import javax. jws. webService; @ WebService (endpointInterface = "cn. ljl. sand. jws. chapter1.service. interpretService ") public class InterpretServiceImpl implements InterpretService {public static final String [] CH_NUMS = // force-formatted line feed {" 0 "," 1 "," 2 "," 3 ", "4", "5", "6", "7", "8", "9"}; @ Override public String interpret (int num) {StringBuilder builder = new StringBuilder (Integer. toString (num ). length (); for (int digit = num % 10; num> 0; num = num/10, digit = num % 10) {builder. append (CH_NUMS [digit]);} builder. reverse (); return builder. toString ();}}
Note: Service publisher
package cn.ljl.sand.jws.chapter1.service; import javax.xml.ws.Endpoint; public class InterpretServicePublisher { public static void main(String[] args) { String address = "http://localhost:6666/service/interpret"; InterpretService service = new InterpretServiceImpl(); Endpoint.publish(address, service); }}
According to the Code, the wsdl URL is http: // localhost: 6666/service/interpret? Wsdl. You can enter this address in your browser to view its content. But we are not ready to explain it. Client Test
From Weizhi note (Wiz)