调用webservice:通过所给的xml文件来远程调用service服务



<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://localhost:8081/axis/services/testaxis" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8081/axis/services/testaxis" xmlns:f="http://localhost:8081/axis/services/testaxis" 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.4
Built _disibledevent=>
<wsdl:part name="getUserReturn" type="soapenc:"/>

</wsdl:message>

<wsdl:message name="getUserRequest">

<wsdl:part name="name" type="soapenc:"/>

</wsdl:message>

<wsdl:message name="authenticateResponse">

<wsdl:part name="authenticateReturn" type="xsd:dateTime"/>

</wsdl:message>

<wsdl:message name="authenticateRequest">

</wsdl:message>

<wsdl:portType name="TestAxis">

<wsdl:operation name="authenticate">

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

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

</wsdl:operation>

<wsdl:operation name="getUser" parameterOrder="name">

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

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

</wsdl:operation>

</wsdl:portType>

<wsdl:binding name="testaxisSoapBinding" type="impl:TestAxis">

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

<wsdl:operation name="authenticate">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="authenticateRequest">

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

</wsdl:input>

<wsdl:output name="authenticateResponse">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ="http://localhost:8081/axis/services/testaxis" use="encoded"/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name="getUser">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="getUserRequest">

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

</wsdl:input>

<wsdl:output name="getUserResponse">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ="http://localhost:8081/axis/services/testaxis" use="encoded"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:service name="TestAxisService">

<wsdl:port binding="impl:testaxisSoapBinding" name="testaxis">

<wsdlsoap:address location="http://192.168.4.55:8081/axis/services/testaxis"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>


思路方法

package com.yysoft.chen;

import java.rmi.RemoteException;
import java.util.Date;

import javax.xml..QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.ServiceFactory;

import org.apache.tools.ant.types.resolver.ApacheCatalog;
public TextService {
public void (String args) {
testaxiss;
}

public void testaxis{
try {
QName servicename= QName("http://192.168.4.55:8081/axis/services/testaxis","TestAxisService");
Service service=ServiceFactory.Instance.createService(servicename);
Call call=service.createCall;
call.TargetEndpoAddress("http://192.168.4.55:8081/axis/services/testaxis?wsdl");


QName operationname= QName("http://localhost:8081/axis/services/testaxis","authenticate");
call.OperationName(operationname);
QName name= QName("http://www.w3.org/2001/XMLSchema","dateTime");
call.ReturnType(name, java.util.Date.);
Date d= (Date) call.invoke( Object{});
.out.prln(d.toLocaleString);

} catch (ServiceException e) {
// TODO Auto-generated catch block
e.prStackTrace;
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.prStackTrace;
}
}

public void testaxiss{
try {
QName servicename= QName("http://192.168.4.55:8081/axis/services/testaxis","TestAxisService");
Service service=ServiceFactory.Instance.createService(servicename);
Call call=service.createCall;
call.TargetEndpoAddress("http://192.168.4.55:8081/axis/services/testaxis?wsdl");

QName operationname= QName("http://localhost:8081/axis/services/testaxis","getUser");
call.OperationName(operationname);

QName namename= QName("http://schemas.xmlsoap.org/soap/encoding/","name");
call.addParameter("name", namename, javax.xml.rpc.ParameterMode.IN);

QName name= QName("http://schemas.xmlsoap.org/soap/encoding/","");
call.ReturnType(name, String.); //将设好返回类型装载入call中
String version=(String)call.invoke( Object{"fffsad"});
.out.prln(version);

} catch (ServiceException e) {
// TODO Auto-generated catch block
e.prStackTrace;
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.prStackTrace;
}
}

public void version{
try {
//Qname("名称空间","对应名称");

//设置服务名及对应名称空间
QName servicename= QName("http://localhost:8081/axis/services/Version","VersionService");
//根据对应名称空间和服务名称创建个服务
Service service=ServiceFactory.Instance.createService(servicename);
//通过service创建个call(思路方法)
Call call=service.createCall;
call.TargetEndpoAddress("http://192.168.4.55:8081/axis/services/Version?wsdl");

//设置思路方法名及对应名称空间
QName operationname= QName("http://localhost:8081/axis/services/Version","getVersion");
call.OperationName(operationname); //将设好思路方法装载入call中
//设置返回类型及对应名称空间
QName name= QName("http://www.w3.org/2001/XMLSchema","");
call.ReturnType(name, String.); //将设好返回类型装载入call中
String version=(String)call.invoke( Object{});
.out.prln(version);

} catch (ServiceException e) {
// TODO Auto-generated catch block
e.prStackTrace;
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.prStackTrace;
}
}
}

Tags:  如何调用webservice vb调用webservice java调用webservice 调用webservice

延伸阅读

最新评论

发表评论