请教如何解析 .svc?wsdl 服务描述? 用java1客户端如何调用接口
本帖最后由 viviandew 于 2012-11-22 10:43:17 编辑 http://ip:port/CarBar.svc?wsdl 如下:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://tempuri.org/"
xmlns:wsa10="http://www.w3.org/2005/08/addressing"
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://tempuri.org/" name="CarBar">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import namespace="http://tempuri.org/" schemaLocation="http://ip:port/CarBar.svc?xsd=xsd0"/>
<xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="http://ip:port/CarBar.svc?xsd=xsd1"/>
<xsd:import namespace="http://schemas.datacontract.org/2004/07/Easyway.Interfaces.Publish.Entities" schemaLocation="http://ip:port/CarBar.svc?xsd=xsd2"/>
<xsd:import namespace="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses" schemaLocation="http://ip:port/CarBar.svc?xsd=xsd3"/>
<xsd:import namespace="http://schemas.datacontract.org/2004/07/System.Data" schemaLocation="http://ip:port/CarBar.svc?xsd=xsd4"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ICarBar_GetCar_InputMessage">
<wsdl:part name="parameters" element="tns:GetCar"/>
</wsdl:message>
<wsdl:message name="ICarBar_GetCar_OutputMessage">
<wsdl:part name="parameters" element="tns:GetCarResponse"/>
</wsdl:message>
<wsdl:portType name="ICarBar">
<wsdl:operation name="GetCar">
<wsdl:input message="tns:ICarBar_GetCar_InputMessage" wsaw:Action="http://tempuri.org/ICarBar/GetCar"/>
<wsdl:output message="tns:ICarBar_GetCar_OutputMessage" wsaw:Action="http://tempuri.org/ICarBar/GetCarResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Carhttpwcf" type="tns:ICarBar">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetCar">
<soap:operation style="document" soapAction="http://tempuri.org/ICarBar/GetCar"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CarBar">
<wsdl:port name="Carhttpwcf" binding="tns:Carhttpwcf">
<soap:address location="http://ip:port/CarBar.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
String urlname = "http://ip:port/CarBar.svc?wsdl" ;
Service s = new Service();
Call call = (Call) s.createCall();
call.setTimeout(new Integer(5000));
call.setOperation( "ICarBar/GetCar" );//或GetCar
call.setTargetEndpointAddress(urlname);
Object[] fn01 = {};
String val = (String)call.invoke(fn01);
System.out .println( "GetCar():" + val);
URL u = new URL("http://ip:port/CarBar.svc?wsdl");
Service s = new Service();
CarhttpwcfStub w = new CarhttpwcfStub(u,s);
w.getCar();
call.setUseSOAPAction(true);返回结果跟第二种是一致的。用soapUI测试了一下 发现是接口的问题。
call.setSOAPActionURI("http://tempuri.org/ICarBar/GetCar");
call.setEncodingStyle(null);
call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);