webservice trainning plan

=================================

webservice training plan

=================================

1. Write a HelloWorld with JAX-WS knowledge.

2. XSD, For the request, it should be contain below element, schema, element, attribute, restriction, simpleType, group, attributeGroup, choice, complexType, union, unique, sequence, and understand how to used these element.

3. WSDL: Understand how to use type, message, operation, porttype, Binding, port, service

reference link: http://www.w3.org/TR/wsdl

4. Understand what's the SOAP, and SOAP structure
http://www.w3.org/TR/2007/REC-soap12-part0-20070427/.

5. What's the JSON and how to use it, a demo is required, and understand the important annotation, such as BindingType, WebParam and so on.

http://jax-ws-commons.java.net/json/


6.(Optional) Understand the Handler and MessageContext concept, and finish a demo. http://jax-ws.dev.java.net/articles/handlers_introduction.html
http://jax-ws.dev.java.net/articles/MessageContext.html
http://www.javaworld.com/javaworld/jw-02-2007/jw-02-handler.html

 

 

=================================
一、wsdl/xsd
=================================
wsdl and xsd is a contract between service and client. mostly, we define the wsdl and xsd first, and develping service according
to wsdl/xsd, and publish wsdl.
the client get wsdl and develop client artifacts according to wsdl.

demo wsdl/xsd

=================================
二、SOAP
=================================
SOAP is a type of comunication protocol, be used to exchange info between Applications,
it is based on XML and can be extended easily, it group informations into an SOAP message
and the SOAP message can be payloaded by http/jms/smtp etc.

Example:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getGeoIPContextResponse xmlns="http://WebXml.com.cn/">
      <getGeoIPContextResult>
        <string>string</string>
        <string>string</string>
      </getGeoIPContextResult>
    </getGeoIPContextResponse>
  </soap:Body>
</soap:Envelope>


===================================
三、develop model
===================================
start from java
start from wsdl/xsd

===================================
四、binding type
===================================

1、SOAPBinding

---------------
Request Message
---------------
POST /WebServices/IpAddressSearchWebService.asmx HTTP/1.1
Host: www.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getGeoIPContext"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getGeoIPContext xmlns="http://WebXml.com.cn/" />
  </soap:Body>
</soap:Envelope>

----------------
Response Message
----------------
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getGeoIPContextResponse xmlns="http://WebXml.com.cn/">
      <getGeoIPContextResult>
        <string>string</string>
        <string>string</string>
      </getGeoIPContextResult>
    </getGeoIPContextResponse>
  </soap:Body>
</soap:Envelope>
 
2、HTTPBinding(get/post)

-----
POST
-----
POST /WebServices/IpAddressSearchWebService.asmx/getGeoIPContext HTTP/1.1
Host: www.webxml.com.cn
Content-Type: application/x-www-form-urlencoded
Content-Length: length


HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns="http://WebXml.com.cn/">
  <string>string</string>
  <string>string</string>
</ArrayOfString>
------
GET
------
GET /WebServices/IpAddressSearchWebService.asmx/getGeoIPContext? HTTP/1.1
Host: www.webxml.com.cn

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns="http://WebXml.com.cn/">
  <string>string</string>
  <string>string</string>
</ArrayOfString>

============================
五、Message Style
============================
------------
rpc/encoding
------------
Strengths:
1、the operation name appears in the request message,so the receiver can dispaching this message
 to the implementation of the operation easily
Weaknesses:
1、The type encoding info will degrades throughput performance.
2、you cannot easily validate this message since only part of lines contain things defined in a schema; the rest of the soap:body contents comes from WSDL definitions.
3、RPC/encoded is not WS-I compliant.

------------
RPC/literal
------------
Strengths:
1、the operation name appears in the request message,so the receiver can dispaching this message
 to the implementation of the operation easily
2、The type encoding info is eliminated.
3、RPC/literal is WS-I compliant.
Weaknesses:
1、you cannot easily validate this message since only part of lines contain things defined in a schema; the rest of the soap:body contents comes from WSDL definitions.

----------------
Document/encoded
----------------
Nobody follows this style. It is not WS-I compliant. So let's move on.

---------------------
Document/literal/BARE
---------------------
Strengths
1、There is no type encoding info.
2、You can finally validate this message with any XML validator. Everything within the soap:body is defined in a schema.
3、Document/literal is WS-I compliant.
Weaknesses
1、The WSDL is getting a bit more complicated. This is a very minor weakness, however, since WSDL is not meant to be read by humans.
2、The operation name in the SOAP message is lost. Without the name, dispatching can be difficult, and sometimes impossible.
3、WS-I only allows one child of the soap:body in a SOAP message. Document/literal/BARE can take more than one part child.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
 <S:Header />
 <S:Body>
  <ns2:authorize xmlns:ns2="http://www.cmbchina.com/Credit">
   <creditCard>
    <ns2:cardNumber>
     6225998778786540
    </ns2:cardNumber>
     <ns2:name>
      <ns2:firstName>
       yang
      </ns2:firstName>
       <ns2:middleInitial xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:nil="true" />
       <ns2:lastName>qiang</ns2:lastName>
     </ns2:name>
     <ns2:expirationDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:nil="true" />
    </creditCard>
  </ns2:authorize>
 </S:Body>
</S:Envelope>

-------------------------
Document/literal/WRAPPED
-------------------------
Strengths
1、There is no type encoding info.
2、Everything that appears in the soap:body is defined by the schema, so you can easily validate this message.
3、Once again, you have the method name in the SOAP message.
4、Document/literal is WS-I compliant, and the wrapped pattern meets the WS-I restriction that the SOAP message's soap:body has only one child.
Weaknesses
1、The WSDL is even more complicated.

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
 <S:Header />
 <S:Body>
  <ns2:authorize xmlns:ns2="http://www.cmbchina.com/Credit">
   <creditCard>
    <ns2:cardNumber>
     6225998778786540
    </ns2:cardNumber>
     <ns2:name>
      <ns2:firstName>
       yang
      </ns2:firstName>
      <ns2:middleInitial xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:nil="true" />
      <ns2:lastName>qiang</ns2:lastName>
     </ns2:name>
     <ns2:expirationDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:nil="true" />
   </creditCard>
  </ns2:authorize>
 </S:Body>
</S:Envelope>

=====================
六、Handler
=====================
allows the separation of the most fundamental concerns of application software in Web services development,
effectively abstracting the system service into handlers and leaving the clients and services to focus on business logic.

Handler
 --LogicalHandler
 --SOAPHandler
Protocol handlers are specific to a protocol and may access or change the protocol-specific aspects of a message
Logical handlers are protocol-agnostic and act only on the payload of a message

MessageContext
 --SOAPMessageContext
 --LogicalMessageContext

SOAPMessageContext's getMessage() method provides the whole SOAP envelope (both SOAP header and body parts).
The same method on a LogicalMessageContext object returns only the payload of the message in exchange.
In the SOAP binding case, this means LogicalMessageContext's getMessage() only returns the SOAP body part.


======================================
Dispatch APIs:
Web service client applications may choose to work at the XML message level by using the Dispatch<T> APIs.
======================================

======================================
Dynamic Proxy:
In this approach client side invokes Web services via a dynamic proxy. T
he proxies for the Web Service are created from the generated Service and service endpoint interfaces.
Once the proxies are created. the client application can invoke methods on those proxies just like a standard implementation of those interfaces.
The sections below describe this process more detail.
======================================


======================================
Provider interface
Web Service endpoints may choose to work at the XML message level by implementing the Provider interface.
======================================

======================================
MTOM and XOP:

MTOM (Message Transmission and Optimization Mechanism) together with XOP (XML Binary Optimized Packaging) defines how an XML binary data such as xs:base64Binary or xs:hexBinary can be optimally transmitted over the wire.
XML type, such as xs:base64Binary is sent in lined inside the SOAP envelope. This gets quite in-efficient when the data size is more, for example a SOAP endpoint that exchanges images/songs etc. MTOM specifies how XOP packaging can be used to send the binary data optimally.
======================================

======================================
Validate XML against XSD
======================================
 //init validator factory
 SchemaFactory fac = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
 Schema schema = fac.newSchema(new File("CreditCardSchema.xsd"));
 javax.xml.validation.Validator validator = schema.newValidator();
 Source source = new StreamSource(new File("CreditCard.xml"));
 validator.validate(source);
======================================


======================================
JAXB-unmarshaller
======================================
 JAXBContext context = JAXBContext.newInstance("com.cmbchina.credit");
 Unmarshaller unmarshaller = context.createUnmarshaller();
 JAXBElement<CreditCard> el = (JAXBElement<CreditCard>)unmarshaller.unmarshal(new File("CreditCard.xml"));
 CreditCard au = el.getValue();
 cardNum = au.getCardNumber();
 System.out.println("cardNum:"+cardNum+"\r\ndate:"+au.getExpirationDate().getYear()+"\r\nname:"+au.getName().getFirstName()+au.getName().getMiddleInitial()+au.getName().getLastName());
   
======================================


======================================
JAXB-marshaller
======================================

======================================


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值