Java 如何使用代码生成的SOAP客户端?
我需要用java为您创建一个Soap客户端 我改变了使用wsimport从WSDL生成代码的方式。我的问题是,我不知道如何使用它。更具体地说,如何对服务进行Soap调用,以便验证税务id 我甚至尝试了多种方法,使用从soapui生成的代码,从Intellij生成的代码,等等。它们都非常不同,我有点陷入了这种状态。有人能帮我点一下吗?谢谢 这对我来说似乎相当困难,我已经花了这么多时间在这上面,但没有结果。我还尝试了在谷歌上找到的所有教程。我猜这个问题的答案将来会对很多人有所帮助 以下是生成的代码: CheckTinService.java:Java 如何使用代码生成的SOAP客户端?,java,web-services,soap,wsdl,jax-ws,Java,Web Services,Soap,Wsdl,Jax Ws,我需要用java为您创建一个Soap客户端 我改变了使用wsimport从WSDL生成代码的方式。我的问题是,我不知道如何使用它。更具体地说,如何对服务进行Soap调用,以便验证税务id 我甚至尝试了多种方法,使用从soapui生成的代码,从Intellij生成的代码,等等。它们都非常不同,我有点陷入了这种状态。有人能帮我点一下吗?谢谢 这对我来说似乎相当困难,我已经花了这么多时间在这上面,但没有结果。我还尝试了在谷歌上找到的所有教程。我猜这个问题的答案将来会对很多人有所帮助 以下是生成的代码:
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "checkTinService", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin", wsdlLocation = "https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl")
public class CheckTinService
extends Service
{
private final static URL CHECKTINSERVICE_WSDL_LOCATION;
private final static WebServiceException CHECKTINSERVICE_EXCEPTION;
private final static QName CHECKTINSERVICE_QNAME = new QName("urn:ec.europa.eu:taxud:tin:services:checkTin", "checkTinService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
CHECKTINSERVICE_WSDL_LOCATION = url;
CHECKTINSERVICE_EXCEPTION = e;
}
public CheckTinService() {
super(__getWsdlLocation(), CHECKTINSERVICE_QNAME);
}
public CheckTinService(WebServiceFeature... features) {
super(__getWsdlLocation(), CHECKTINSERVICE_QNAME);
}
public CheckTinService(URL wsdlLocation) {
super(wsdlLocation, CHECKTINSERVICE_QNAME);
}
public CheckTinService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, CHECKTINSERVICE_QNAME);
}
public CheckTinService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public CheckTinService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName);
}
/**
*
* @return
* returns CheckTinPortType
*/
@WebEndpoint(name = "checkTinPort")
public CheckTinPortType getCheckTinPort() {
return super.getPort(new QName("urn:ec.europa.eu:taxud:tin:services:checkTin", "checkTinPort"), CheckTinPortType.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns CheckTinPortType
*/
@WebEndpoint(name = "checkTinPort")
public CheckTinPortType getCheckTinPort(WebServiceFeature... features) {
return super.getPort(new QName("urn:ec.europa.eu:taxud:tin:services:checkTin", "checkTinPort"), CheckTinPortType.class, features);
}
private static URL __getWsdlLocation() {
if (CHECKTINSERVICE_EXCEPTION!= null) {
throw CHECKTINSERVICE_EXCEPTION;
}
return CHECKTINSERVICE_WSDL_LOCATION;
}
}
CheckTinPortType.java
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.Holder;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import eu.europa.ec.taxud.tin.services.checktin.types.ObjectFactory;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*
*/
@WebService(name = "checkTinPortType", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin")
@XmlSeeAlso({
ObjectFactory.class
})
public interface CheckTinPortType {
/**
*
* @param tinNumber
* @param countryCode
* @param validStructure
* @param requestDate
* @param validSyntax
*/
@WebMethod
@RequestWrapper(localName = "checkTin", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin:types", className = "eu.europa.ec.taxud.tin.services.checktin.types.CheckTin")
@ResponseWrapper(localName = "checkTinResponse", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin:types", className = "eu.europa.ec.taxud.tin.services.checktin.types.CheckTinResponse")
public void checkTin(
@WebParam(name = "countryCode", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin:types", mode = WebParam.Mode.INOUT)
Holder<String> countryCode,
@WebParam(name = "tinNumber", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin:types", mode = WebParam.Mode.INOUT)
Holder<String> tinNumber,
@WebParam(name = "requestDate", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin:types", mode = WebParam.Mode.OUT)
Holder<XMLGregorianCalendar> requestDate,
@WebParam(name = "validStructure", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin:types", mode = WebParam.Mode.OUT)
Holder<Boolean> validStructure,
@WebParam(name = "validSyntax", targetNamespace = "urn:ec.europa.eu:taxud:tin:services:checkTin:types", mode = WebParam.Mode.OUT)
Holder<Boolean> validSyntax);
}
导入javax.jws.WebMethod;
导入javax.jws.WebParam;
导入javax.jws.WebService;
导入javax.xml.bind.annotation.xmlsee;
导入javax.xml.datatype.XMLGregorianCalendar;
导入javax.xml.ws.Holder;
导入javax.xml.ws.RequestWrapper;
导入javax.xml.ws.ResponseWrapper;
导入eu.europa.ec.taxud.tin.services.checktin.types.ObjectFactory;
/**
*这个类是由JAX-WSRI生成的。
*JAX-WSRI 2.2.4-b01
*生成的源版本:2.2
*
*/
@WebService(name=“checkTinPortType”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin”)
@XmlSeeAllow({
ObjectFactory.class
})
公共接口CheckTinPortType{
/**
*
*@param tinNumber
*@param countryCode
*@param-validStructure
*@param requestDate
*@param validSyntax
*/
@网络方法
@RequestWrapper(localName=“checkTin”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin:types”,className=“eu.europa.ec.taxud.tin.services.checkTin.types.checkTin”)
@ResponseWrapper(localName=“checkTinResponse”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin:types”,className=“eu.europa.ec.taxud.tin.services.checkTin.types.checkTinResponse”)
公共作废支票(
@WebParam(name=“countryCode”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin:types”,mode=WebParam.mode.INOUT)
持有人国家代码,
@WebParam(name=“tinNumber”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin:types”,mode=WebParam.mode.INOUT)
支架编号,
@WebParam(name=“requestDate”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin:types”,mode=WebParam.mode.OUT)
持有人申请日期,
@WebParam(name=“validStructure”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin:types”,mode=WebParam.mode.OUT)
持有人有效结构,
@WebParam(name=“validSyntax”,targetNamespace=“urn:ec.europa.eu:taxud:tin:services:checkTin:types”,mode=WebParam.mode.OUT)
持有人(有效综合税);
}
ObjectFactory.java:
import com.exiqon.core.eu.europa.ec.taxud.tin.services.checktin.types.CheckTin;
import com.exiqon.core.eu.europa.ec.taxud.tin.services.checktin.types.CheckTinResponse;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the eu.europa.ec.taxud.tin.services.checktin.types package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: eu.europa.ec.taxud.tin.services.checktin.types
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link eu.europa.ec.taxud.tin.services.checktin.types.CheckTin }
*
*/
public CheckTin createCheckTin() {
return new CheckTin();
}
/**
* Create an instance of {@link CheckTinResponse }
*
*/
public CheckTinResponse createCheckTinResponse() {
return new CheckTinResponse();
}
}
import com.exiqon.core.eu.europa.ec.taxud.tin.services.checktin.types.checktin;
导入com.exiqon.core.eu.europa.ec.taxud.tin.services.checktin.types.CheckTinResponse;
导入javax.xml.bind.annotation.XmlRegistry;
/**
*此对象包含每个对象的工厂方法
*Java内容接口和Java元素接口
*在eu.europa.ec.taxud.tin.services.checktin.types包中生成。
*ObjectFactory允许您以编程方式
*构造Java表示的新实例
*用于XML内容。XML的Java表示
*内容可以由模式派生的接口组成
*和表示模式绑定的类
*类型定义、元素声明和模型
*小组。每种方法的工厂方法如下:
*本课程提供。
*
*/
@XmlRegistry
公共类对象工厂{
/**
*创建一个新的ObjectFactory,该工厂可用于为以下包创建架构派生类的新实例:eu.europa.ec.taxud.tin.services.checktin.types
*
*/
公共对象工厂(){
}
/**
*创建{@link eu.europa.ec.taxud.tin.services.checktin.types.checktin}的实例
*
*/
公共CheckTin createCheckTin(){
返回新的CheckTin();
}
/**
*创建{@link CheckTinResponse}的实例
*
*/
公共CheckTinResponse createCheckTinResponse(){
返回新的CheckTinResponse();
}
}
CheckTinResponse.java:
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="countryCode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="tinNumber" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="requestDate" type="{http://www.w3.org/2001/XMLSchema}date"/>
* <element name="validStructure" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
* <element name="validSyntax" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"countryCode",
"tinNumber",
"requestDate",
"validStructure",
"validSyntax"
})
@XmlRootElement(name = "checkTinResponse")
public class CheckTinResponse {
@XmlElement(required = true)
protected String countryCode;
@XmlElement(required = true)
protected String tinNumber;
@XmlElement(required = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar requestDate;
protected boolean validStructure;
protected Boolean validSyntax;
/**
* Gets the value of the countryCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCountryCode() {
return countryCode;
}
/**
* Sets the value of the countryCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCountryCode(String value) {
this.countryCode = value;
}
/**
* Gets the value of the tinNumber property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTinNumber() {
return tinNumber;
}
/**
* Sets the value of the tinNumber property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTinNumber(String value) {
this.tinNumber = value;
}
/**
* Gets the value of the requestDate property.
*
* @return
* possible object is
* {@link XMLGregorianCalendar }
*
*/
public XMLGregorianCalendar getRequestDate() {
return requestDate;
}
/**
* Sets the value of the requestDate property.
*
* @param value
* allowed object is
* {@link XMLGregorianCalendar }
*
*/
public void setRequestDate(XMLGregorianCalendar value) {
this.requestDate = value;
}
/**
* Gets the value of the validStructure property.
*
*/
public boolean isValidStructure() {
return validStructure;
}
/**
* Sets the value of the validStructure property.
*
*/
public void setValidStructure(boolean value) {
this.validStructure = value;
}
/**
* Gets the value of the validSyntax property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isValidSyntax() {
return validSyntax;
}
/**
* Sets the value of the validSyntax property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setValidSyntax(Boolean value) {
this.validSyntax = value;
}
}
import javax.xml.bind.annotation.XmlAccessType;
导入javax.xml.bind.annotation.XmlAccessorType;
导入javax.xml.bind.annotation.xmlement;
导入javax.xml.bind.annotation.XmlRootElement;
导入javax.xml.bind.annotation.XmlSchemaType;
导入javax.xml.bind.annotation.XmlType;
导入javax.xml.datatype.XMLGregorianCalendar;
/**
*匿名复杂类型的Java类。
*
*以下架构片段指定此类中包含的预期内容。
*
*
*complexType>
*complexContent>
*限制基数=”{http://www.w3.org/2001/XMLSchema}任何类型“>
*序列>
*元素名称=“国家代码”类型=”{http://www.w3.org/2001/XMLSchema}字符串“/>
*元素名称=“tinNumber”类型=”{http://www.w3.org/2001/XMLSchema}字符串“/>
*元素名称=“requestDate”类型=”{http://www.w3.org/2001/XMLSchema}日期“/>
*元素名称=“有效结构”类型=”{http://www.w3.org/2001/XMLSchema}布尔“/>
*元素名称=“validSyntax”类型=”{http://www.w3.org/2001/XMLSchema}布尔值“minOccurs=”0“/>
*/顺序>
*/限制>
*/complexContent>
*/complexType>
*
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=),比例={
“国家代码”,
“tinNumber”,
“请求日期”,
“有效结构”,
“有效语法”
})
@XmlRootElement(name=“checkTinResponse”)
公共类CheckTinResponse{
@XmlElement(必需=true)
受保护的字符串编码;
@XmlElement(必需=true)
受保护的字符串编号;
@XmlElement(必需=true)
@XmlSchemaTy
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="countryCode" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="tinNumber" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"countryCode",
"tinNumber"
})
@XmlRootElement(name = "checkTin")
public class CheckTin {
@XmlElement(required = true)
protected String countryCode;
@XmlElement(required = true)
protected String tinNumber;
/**
* Gets the value of the countryCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCountryCode() {
return countryCode;
}
/**
* Sets the value of the countryCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCountryCode(String value) {
this.countryCode = value;
}
/**
* Gets the value of the tinNumber property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTinNumber() {
return tinNumber;
}
/**
* Sets the value of the tinNumber property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTinNumber(String value) {
this.tinNumber = value;
}
}
public class WsTest {
public static void main(String[] args) {
try {
CheckTinService checkTinService = new CheckTinService();
CheckTinPortType portType = checkTinService.getPort(CheckTinPortType.class);
Holder<String> code = new Holder<String>("DE");
Holder<String> tin = new Holder<String>("12346789");
Holder<XMLGregorianCalendar> requestDate = new Holder<>();
Holder<Boolean> validStructure = new Holder<>();
Holder<Boolean> validSyntax = new Holder<>();
portType.checkTin(code, tin, requestDate, validStructure, validSyntax);
System.out.println("requestDate : " + requestDate.value);
System.out.println("validStructure : " + validStructure.value);
System.out.println("validSyntax : " + validSyntax.value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:tin:services:checkTin:types">
<soapenv:Header/>
<soapenv:Body>
<urn:checkTin>
<urn:countryCode>DE</urn:countryCode>
<urn:tinNumber>12346789</urn:tinNumber>
</urn:checkTin>
</soapenv:Body>
</soapenv:Envelope>