1
2022年10月
所有的数据都是资源。代表客户 每个资源可以有不同的表示 每个资源都有自己的唯一标识(URI)
用SOAP实现Web服务是一种节省时间的方法,应该找到一种新的方法来实现WS
与消息格式耦合 -与wS编码耦合 -解析和组装SOAP -需要一个WSDL来描述Ws的细节 -需要一个从WSDL生成的代理
只要支持webservice企业版的工具,就可以生成相应的public辅助类。
prices =new HashMap<StringDouble>() prices.put("Blackwell Toaster",24.95);
prices.put("ZapXpress Microwave Oven",49.95);
在配置文件里面获取客户端,在客户端里面wdsl文件的位置在如下所示,在wdsl文件上生成相应的对应端
在包装好的web里面去执行getwebservice tempiate方法,
marshalSendAndReceive("http://localhost:8080/ws/countries,request
new SoapActionCallback
去发出请求返回结果之后就得到了。
在“/ws”这个位置上对应的countrises生成的。
public DefaultWsdl11Definition defaultWsdl11Definition(Xsdschema countriesSchema){ DefaultWsdl11Definition wsdl11Definition=new DefaultWsdl11Definition(); wsdl11Definition.setPortTypeName"CountriesPort" wsdl11Definition.setLocationUri/ws
wsdl11Definition.setTargetNamespace"http://spring.io/guides/gs-producing-web-service") wsdl11Definition.setSchema(countriesSchema); return wsdl11Definition:
10、对着http://localhost:8880/ws/countries这个位置发这个请求,然后再返回,结果之后就得到了response。
继承WebServiceGatewaySupport{, 拿到之后就可以执行相应的调用。代码如下
private static final Logger log =LoggerFactorygetLogger(CountryClient.class)
public GetCountryResponse getCountry(String country){
GetCountryRequest request=new GetCountryRequest() request.setName(country);
代码如下:
private static final Logger log =LoggerFactorygetLogger(CountryClient.class)
public GetCountryResponse getCountry(String country){
GetCountryRequest request=new GetCountryRequest) request.setName(country);
log.info("Requesting location for"+country)
GetCountryResponse response=(GetCountryResponse)getWebServiceTemplate)
.marshalSendAndReceive("http://localhost:8080/ws/countries"request
new SaapActionCallback(
"http://spring.io/guides/gs-producing-web-service/GetCountryRequest"));
return response
从http://lacalhost:8080/ws/cauntries.wsdl这个位置上去生成WSDL的文件,去编译生成generate这个动作,就会产生java这一端的端口和Proxy。
因为是从soap里面去解析内容过来,这有一个叫做name的东西,可以看到是在request上面get name ,就把name取出来了,这样的映射关系
public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request){ GetCountryResponse response=new GetCountryResponse();
response.setCountry(countryRepositoryfindCountry(request.getName()));
一种是可以用postman,使用后会得到一个返回体的信封。含义就是没有发出Java代码,只要是有这样请求的客户端就会有返回体的结果
一种是通过soapenv信封,也可以自己组一个信封。
xmins:soapenv="http://schemas.xmsoaporg/soap/envelope/
xmins:gs="http://spring.io/guides/gs-producing-web-service"><soapenv:Header/><soapenv:Body>
<gs:getCountryRequest>
<gs:name>Spain</gs:name></gs:getCountryRequest></soapenv:Body></soapenv:Envelope>
打开一个pom文件,编译好之后一定要对应jaxb.2这个安装包,再去进行一次编译才能产生wdsl文件。
重要的是位置在哪,在位置上可以访问到外部服务
wsdl11Definition.setTargetNamespace("http://springio/guides/gs-producing-web-service") wsdl11Definition.setSchema(countriesSchema); return wsdl11Definition;
1、在WebServiceConfig.java上setLocationUri(“/ws”)这个位置上能访问("CountriesPort")的web服务。
处理过程就是在不断的在转换客户端和服务器端之间的状态,那么服务器和客户端之间传递的消息这消息而不需要一个ws SQL文件再去描述它,所以它是自描述
用HTTP里的 GET表示read POST表示create PUT-表示update DELETE表示delete
带来了五点问题:-与消息格式耦合-与ws编码耦合-解析和组装SOAP-需要WSDL来描述详细的软件-需要从WSDL生成的代理