One of the articles of Android calling Java WebService

 

1. Server WebService

  1. Server environment configuration

         MyEclipse 10.0、Tomcat6.0、JDK6.0。

  2. Download the axis related jar package.

    

    

  3. Create webservice.

  • Open MyEclipse and create a new web project.
  • First add the wsdd file (server-config.wsdd) in the WEB-INF directory
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  

<globalConfiguration>
  <parameter name="sendMultiRefs" value="true"/>
  <parameter name="disablePrettyXML" value="true"/>
  <parameter name="dotNetSoapEncFix" value="true"/>
  <parameter name="enableNamespacePrefixOptimization" value="false"/>
  <parameter name="sendXMLDeclaration" value="true"/>
  <parameter name="sendXsiTypes" value="true"/>
  <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
</globalConfiguration>

  <handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>   
  <service name="webCallService" provider="java:RPC">   
     <parameter name="className" value="com.gc.Login"/>
     <parameter name="scope" value="request"/>
     <parameter name="allowedMethods" value="*"/>
     <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
  </service>   
  <transport name="http">   
     <requestFlow>   
        <handler type="URLMapper"/>   
     </requestFlow>   
  </transport>   
</deployment>
server-config.wsdd

  The web.xml configuration is as follows,

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>    
  <servlet>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
web.xml

  service test class,

public class Login {
     public String callService(String str1,String str2){
         
         // Logical code... 
         
         StringBuffer sb = new StringBuffer();
         sb.append(str1);
         sb.append("->");
         sb.append(str2);
         
         //...
         
         return sb.toString();
     }
}
View Code

     4. Test whether the connection is successful. http://localhost:8088/webservice/services/webCallService?wsdl

  The connection is successful as shown below,

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://localhost:8088/webservice/services/webCallService" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8088/webservice/services/webCallService" xmlns:intf="http://localhost:8088/webservice/services/webCallService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.2.1
Built on Jun 14, 2005 (09:15:57 EDT)-->

   <wsdl:message name="callServiceResponse">

      <wsdl:part name="callServiceReturn" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="callServiceRequest">

      <wsdl:part name="str1" type="xsd:string"/>

      <wsdl:part name="str2" type="xsd:string"/>

   </wsdl:message>

   <wsdl:portType name="Login">

      <wsdl:operation name="callService" parameterOrder="str1 str2">

         <wsdl:input message="impl:callServiceRequest" name="callServiceRequest"/>

         <wsdl:output message="impl:callServiceResponse" name="callServiceResponse"/>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="webCallServiceSoapBinding" type="impl:Login">

      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="callService">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="callServiceRequest">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://gc.com" use="encoded"/>

         </wsdl:input>

         <wsdl:output name="callServiceResponse">

            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8088/webservice/services/webCallService" use="encoded"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="LoginService">

      <wsdl:port binding="impl:webCallServiceSoapBinding" name="webCallService">

         <wsdlsoap:address location="http://localhost:8088/webservice/services/webCallService"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>
View Code

  The server is now complete. The sequel Android calls Java WebService part two

   

Reprinted in: https://www.cnblogs.com/FCWORLD/p/3490981.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324069820&siteId=291194637