/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. package com.javalessons.ws; 

2. import GoogleSearch.*; 

3. import javax.xml.rpc.ServiceException

4. import java.rmi.RemoteException

5.  

6. public class UseWs

7.   private GoogleSearchPort port; 

8.  

9.   private void doit() 

10.   { 

11.     GoogleSearchService service = new GoogleSearchServiceLocator(); 

12.     try

13.     port = service.getGoogleSearchPort(); 

14.     String s; 

15.     s = port.doSpellingSuggestion( 

16.         "aGooglekeyisneededhere"

17.          "geewhizz" ); 

18.     System.out.println(s); 

19.     } 

20.     catch (ServiceException sex) { sex.printStackTrace(); } 

21.     catch (RemoteException rex) { rex.printStackTrace(); } 

22.   } 

23.   public static void main(String[] args) throws Exception

24.      new UseWs().doit(); 

25.   } 

26.

27. == output : ====== 

28. gee whiz 

29. === GoogleSearch.wsdl ========= 

30. <?xml version="1.0"?> 

31. <definitions name="GoogleSearch" 

32. ...> 

33.   <types> 

34.     <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"  

35.                 targetNamespace="urn:GoogleSearch"

36.              

37.       <xsd:complexType name="GoogleSearchResult"

38.         <xsd:all> 

39.           <xsd:element name="documentFiltering"           type="xsd:boolean"/> 

40.           <xsd:element name="searchComments"              type="xsd:string"/> 

41.           <xsd:element name="estimatedTotalResultsCount"  type="xsd:int"/> 

42. ...etc. 

43.         </xsd:all> 

44.       </xsd:complexType> 

45. ... 

46.     </xsd:schema> 

47.   </types>  

48.  

49.   <message name="doSpellingSuggestion"

50.     <part name="key"            type="xsd:string"/> 

51.     <part name="phrase"         type="xsd:string"/> 

52.   </message> 

53.   <message name="doSpellingSuggestionResponse"

54.     <part name="return"         type="xsd:string"/> 

55.   </message> 

56.  

57.   <portType name="GoogleSearchPort"

58.     <operation name="doSpellingSuggestion"

59.       <input message="typens:doSpellingSuggestion"/> 

60.       <output message="typens:doSpellingSuggestionResponse"/> 

61.     </operation> 

62.   </portType> 

63.  

64.   <binding name="GoogleSearchBinding" type="typens:GoogleSearchPort"

65.     <soap:binding style="rpc" 

66.                   transport="http://schemas.xmlsoap.org/soap/http"/> 

67.     <operation name="doSpellingSuggestion"

68.       <soap:operation soapAction="urn:GoogleSearchAction"/> 

69.       <input

70.         <soap:body... 

71.       <output> 

72.         <soap:body... 

73.     </operation> 

74.   </binding> 

75.  

76.   <!-- Endpoint for Google Web APIs --> 

77.   <service name="GoogleSearchService"

78.     <port name="GoogleSearchPort" binding="typens:GoogleSearchBinding"

79.       <soap:address location="http://api.google.com/search/beta2"/> 

80.     </port> 

81.   </service> 

82. </definitions> 

83.  

84. == SOAP request: ================= 

85. <?xml version="1.0" encoding="UTF-8"?> 

86. <soapenv:Envelope 

87.   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 

88.    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

89.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

90. <soapenv:Body> 

91. <ns1:doSpellingSuggestion 

92.   xmlns:ns1="urn:GoogleSearch" 

93.    soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

94. <key xsi:type="xsd:string">aGooglekeyisneededhere</key> 

95. <phrase xsi:type="xsd:string">geewhizz</phrase> 

96. </.... 

97.  

98. == SOAP response: ================= 

99. <?xml version='1.0' encoding='UTF-8'?> 

100. <SOAP-ENV:Envelope 

101.   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 

102.    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 

103.     xmlns:xsd="http://www.w3.org/1999/XMLSchema"

104. <SOAP-ENV:Body

105. <ns1:doSpellingSuggestionResponse 

106.   xmlns:ns1="urn:GoogleSearch" 

107.    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

108. <return xsi:type="xsd:string">gee whiz</return

109. </... 

110. ======= 

111. public class GoogleSearchServiceLocator 

112. //... 

113.   // Use to get a proxy class for GoogleSearchPort 

114.     private java.lang.String GoogleSearchPort_address 

115.      //= "http://api.google.com/search/beta2"

116.        = "http://127.0.0.1:12345/search/beta2"

117. ======= 

118. org.apache.axis.wsdl.WSDL2Java