java客户端调用C++ GSoap生成的webservice

package com.test.webservice.client;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class TestClent {

	public static void main(String[] args) {
		try {
			String endpoint = "http://www.cmsz.com:7088/getdbpwd/getdbpwdservice"; 
			Service service = new Service(); 
			Call call = (Call)service.createCall(); 
			call.setTargetEndpointAddress(endpoint);	

			call.setOperationName(new QName( 
					"urn:getdbpwd", "getdbpwd")); 
			call.addParameter( "pmsDBUser",null,javax.xml.rpc.ParameterMode.IN); 
			call.setReturnClass(String.class); 
			String temp = (String)call.invoke(new Object[]{"pubdba"}); 
			System.out.println("result: " + temp);
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}


对应的WSDL 文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="getdbpwd"
 targetNamespace="http://www.cmsz.com:7088/getdbpwd/getdbpwd.wsdl"
 xmlns:tns="http://www.cmsz.com:7088/getdbpwd/getdbpwd.wsdl"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:ns="urn:getdbpwd"
 xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
 xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
 xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
 xmlns="http://schemas.xmlsoap.org/wsdl/">

<types>

 <schema targetNamespace="urn:getdbpwd"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:ns="urn:getdbpwd"
  xmlns="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="unqualified"
  attributeFormDefault="unqualified">
  <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
 </schema>

</types>

<message name="getdbpwdRequest">
 <part name="pmsDBUser" type="xsd:string"/>
</message>

<message name="getdbpwdResponse">
 <part name="password" type="xsd:string"/>
</message>

<portType name="getdbpwdPortType">
 <operation name="getdbpwd">
  <documentation>Service definition of function ns__getdbpwd</documentation>
  <input message="tns:getdbpwdRequest"/>
  <output message="tns:getdbpwdResponse"/>
 </operation>
</portType>

<binding name="getdbpwd" type="tns:getdbpwdPortType">
 <SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
 <operation name="getdbpwd">
  <SOAP:operation style="rpc" soapAction=""/>
  <input>
     <SOAP:body use="encoded" namespace="urn:getdbpwd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </input>
  <output>
     <SOAP:body use="encoded" namespace="urn:getdbpwd" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </output>
 </operation>
</binding>

<service name="getdbpwd">
 <documentation>gSOAP 2.7.15 generated service definition</documentation>
 <port name="getdbpwd" binding="tns:getdbpwd">
  <SOAP:address location="http://www.cmsz.com:7088/getdbpwd/getdbpwdservice"/>
 </port>
</service>

</definitions>


你可能感兴趣的:(java客户端调用C++ GSoap生成的webservice)