Ans: we Use this to creat Client side stub from WSDL. It comes with Java SE,So if you have set the path for Java in your system then it automatically available for use. Go to command prompt and type "wsimport",This is use to generate the Stub. Command - Create a folder and name it "Soap webservice" (you can give any name) and then go to that folder from Command prompt and give below command. wsimport -D
2)How to call the WS using client code?
Ans: Code snippet: Pass in programme argument the ip address i.e '212.58.246.79' String ippAddres = arg[0]; GeoIPService ipService = new GeoIPService(); GeoIPServiceSoap geoIPServiceSoap = ipService.getGeoIPServiceSoap(); GeoIP ip = geoIPServiceSoap.getGeoIP(ippAddres); System.out.println("Ip Address: " + ip.getIP() + " Country Name: " + ip.getCountryName());
3)What are the two ways to implement web services?
Ans: There are two ways to implemnt the web services: 1)Service First/code first - (Java file to WSDL generation with annotation @WebService) - (Top Down approach.) 2)Contract First / Interface First -(First WSDL we write then using 'wsimport' we generate the source file) - (Botom Up approach.)
4)How to remove a method from wsdl definition using annotation?
Ans:If we do not use any annotation then all the public method of service class will be autoamtically part of WSDL operation or we used annotation "@WebMethod" to be part of WSDL operation. So if we are using "@WebMethod" then we can add attribute like "@WebMethod(exclude=true)" so that the corresponding method will not be part of WSDL opeartion.
5)What is "targetNamespace" in wsdl?
Ans:It's behaviour similar to java package name. In a WSDL under one 'targetNamespace' all the 5 element were associated. It is autoderived from main java class package name in reverse order. We can specify on our own also.
6)What are the different element in wsdl?
Ans: There were 5 major element in WSDL. Root element "definitions".
1)portType -: It contain's one operation or method name {getPoductCatagories()} and one message as input parameter {getPoductCatagoriesRequest} and one message out put parameter {getPoductCatagoriesResponse}. So message can contains multiple input Object. "
2)types -: There are different object type which will be used to provide as input object or output object.Contains reference of XSD.
3)message -: It contains one single Object as input which might contains multiple object.Like request object will contains i.e "eimessageContext" & "payload" object.
4)binding -: Information about how the operation accept request and send response. like kind of prtocol going to use.
5)service -:It contains details about service End Point. i.e
7)What is binding Style?
Ans: There are two kind of binding style are exist. 1)Document - This is default style.It define external file as 'xsd' file inside
8)JAXB implementation in WS?
Ans: Use follow code snippet: import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; @XmlRootElement(name = "Product") @XmlType(propOrder = { "price", "sku", "name" }) public class Product { private String Name; private String sku; private double price; /* * It is always mandatory to define a no-arg constructor * so that JAXB can initialize the Product object. * */ public Product() { } public Product(String name, String sku, double price) { this.Name = name; this.sku = sku; this.price = price; } @XmlElement(name="ProductName") public String getName() { return Name; } ... }
9)How we can publish Web service without any server?
Ans: use code snippet: public final class SureshMartPublisher { public static void main(String[] args) { Endpoint.publish("http://localhost:4848/productcatalogue", new ProductCatalogue()); } }