访问wsdl的接口

本文介绍了如何访问和测试WSDL文件的接口,具体包括通过http://10.62.226.150:10000/esb/webservice/Jizhandabiao?wsdl获取文件内容,并演示了对其中的createsite接口进行测试的过程。

访问wsdl文件的接口

1.http://10.62.226.150:10000/esb/webservice/Jizhandabiao?wsdl 文件内容

  <? xml version="1.0" encoding="UTF-8" ?>
- < wsdl:definitions name =" JizhandabiaoImplService " targetNamespace =" http://webservice.rpc.other.web.demo.g4studio.org/ " xmlns:ns1 =" http://cxf.apache.org/bindings/xformat " xmlns:soap =" http://schemas.xmlsoap.org/wsdl/soap/ " xmlns:tns =" http://webservice.rpc.other.web.demo.g4studio.org/ " xmlns:wsdl =" http://schemas.xmlsoap.org/wsdl/ " xmlns:xsd =" http://www.w3.org/2001/XMLSchema " >
- < wsdl:types >
- < xs:schema elementFormDefault =" unqualified " targetNamespace =" http://webservice.rpc.other.web.demo.g4studio.org/ " version =" 1.0 " xmlns:tns =" http://webservice.rpc.other.web.demo.g4studio.org/ " xmlns:xs =" http://www.w3.org/2001/XMLSchema " >
  < xs:element name =" IsAlive " type =" tns:IsAlive " />
  < xs:element name =" IsAliveResponse " type =" tns:IsAliveResponse " />
  < xs:element name =" createsite " type =" tns:createsite " />
  < xs:element name =" createsiteResponse " type =" tns:createsiteResponse " />
- < xs:complexType name =" IsAlive " >
  < xs:sequence />
  </ xs:complexType >
- < xs:complexType name =" IsAliveResponse " >
- < xs:sequence >
  < xs:element minOccurs =" 0 " name =" return " type =" xs:string " />
  </ xs:sequence >
  </ xs:complexType >
- < xs:complexType name =" createsite " >
- < xs:sequence >
  < xs:element form =" qualified " minOccurs =" 0 " name =" xmlContent " type =" xs:string " />
  </ xs:sequence >
  </ xs:complexType >
- < xs:complexType name =" createsiteResponse " >
- < xs:sequence >
  < xs:element minOccurs =" 0 " name =" return " type =" xs:string " />
  </ xs:sequence >
  </ xs:complexType >
  </ xs:schema >
  </ wsdl:types >
- < wsdl:message name =" IsAlive " >
  < wsdl:part element =" tns:IsAlive " name =" parameters " />
  </ wsdl:message >
- < wsdl:message name =" IsAliveResponse " >
  < wsdl:part element =" tns:IsAliveResponse " name =" parameters " />
  </ wsdl:message >
- < wsdl:message name =" createsiteResponse " >
  < wsdl:part element =" tns:createsiteResponse " name =" parameters " />
  </ wsdl:message >
- < wsdl:message name =" createsite " >
  < wsdl:part element =" tns:createsite " name =" parameters " />
  </ wsdl:message >
- < wsdl:portType name =" Jizhandabiao " >
- < wsdl:operation name =" IsAlive " >
  < wsdl:input message =" tns:IsAlive " name =" IsAlive " />
  < wsdl:output message =" tns:IsAliveResponse " name =" IsAliveResponse " />
  </ wsdl:operation >
- < wsdl:operation name =" createsite " >
  < wsdl:input message =" tns:createsite " name =" createsite " />
  < wsdl:output message =" tns:createsiteResponse " name =" createsiteResponse " />
  </ wsdl:operation >
  </ wsdl:portType >
- < wsdl:binding name =" JizhandabiaoImplServiceSoapBinding " type =" tns:Jizhandabiao " >
  < soap:binding style =" document " transport =" http://schemas.xmlsoap.org/soap/http " />
- < wsdl:operation name =" IsAlive " >
  < soap:operation soapAction =" " style =" document " />
- < wsdl:input name =" IsAlive " >
  < soap:body use =" literal " />
  </ wsdl:input >
- < wsdl:output name =" IsAliveResponse " >
  < soap:body use =" literal " />
  </ wsdl:output >
  </ wsdl:operation >
- < wsdl:operation name =" createsite " >
  < soap:operation soapAction =" " style =" document " />
- < wsdl:input name =" createsite " >
  < soap:body use =" literal " />
  </ wsdl:input >
- < wsdl:output name =" createsiteResponse " >
  < soap:body use =" literal " />
  </ wsdl:output >
  </ wsdl:operation >
  </ wsdl:binding >
- < wsdl:service name =" JizhandabiaoImplService " >
- < wsdl:port binding =" tns:JizhandabiaoImplServiceSoapBinding " name =" JizhandabiaoImplPort " >
  < soap:address location =" http://10.62.226.150:10000/esb/webservice/Jizhandabiao " />
  </ wsdl:port >
  </ wsdl:service >
  </ wsdl:definitions >

2.测试访问里面createsite接口

/*public static void main(String[] args) throws Exception {

 
String xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<root>" +
"<basestation_id>99999999199892483</basestation_id>" +
"<basestation_name>test增加</basestation_name>" +
"<enodebID>109597</enodebID> " +
"<bsc>0</bsc>" +
"<btsid>1113848</btsid>" +
"<type>4G</type>" +
 
"</root> ";
 
String url = "http://10.62.226.150:10000/esb/webservice/Jizhandabiao?wsdl";
Service serv = new Service();
Call call = (Call) serv.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName("http://webservice.rpc.other.web.demo.g4studio.org/","createsite"));
call.addParameter(new QName("http://webservice.rpc.other.web.demo.g4studio.org/", "xmlContent"), XMLType.XSD_STRING, Class.forName("java.lang.String"), ParameterMode.IN );
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
System.out.println("推送的xml---"+xml);
String str=(String) call.invoke(new Object[] {xml});
System.out.println(str+"----------------推送成功");
}*/
### Spring Boot整合SOAP服务并访问WSDL接口的配置教程与示例 在Spring Boot中整合SOAP服务并访问WSDL接口,通常需要以下几个关键步骤:添加必要的依赖、生成客户端代码、编写调用逻辑以及测试服务。以下是详细的说明和代码示例。 #### 1. 添加依赖 为了使用SOAP服务,可以采用Apache CXF框架来生成客户端代码。在`pom.xml`文件中添加以下依赖[^3]: ```xml <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.2.4</version> </dependency> ``` #### 2. 生成客户端代码 通过`wsimport`工具或Maven插件从WSDL生成客户端代码。例如,在`pom.xml`中添加以下插件[^3]: ```xml <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>3.2.4</version> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://localhost:8080/soapws/articles.wsdl</wsdl> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> ``` 运行`mvn generate-sources`命令后,会根据WSDL生成客户端代码。 #### 3. 编写调用逻辑 创建一个服务类用于调用SOAP服务。例如,使用`SOAPConnector`实现对远程服务的调用[^1]: ```java @Slf4j @Service public class RemoteSoapServiceTest { @Autowired private SOAPConnector soapConnector; public GetPortalRequestResponse callSoapService() { GetPortalRequestResponse soapResponse = (GetPortalRequestResponse) soapConnector.callWebService( "http://example.com/soap/service", // 替换为实际的SOAP服务地址 new GetPortalRequest() // 替换为实际的请求对象 ); log.info("SOAP Response: {}", soapResponse); return soapResponse; } } ``` #### 4. 测试SOAP服务 可以使用工具如SOAP UI来测试生成的WSDL接口[^2]。访问WSDL地址(例如`http://localhost:8080/soapws/articles.wsdl`),然后在SOAP UI中导入该WSDL并发送请求。 #### 5. 完整示例 以下是一个完整的Spring Boot应用示例,展示如何调用SOAP服务[^4]: ```java @Service public class SoapClientService { public String webServicePostTest() { String result = ""; try { SoapClient client = SoapClient.create("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx") .header("SOAPAction", "http://WebXml.com.cn/getMobileCodeInfo") .setMethod("web:getMobileCodeInfo", "http://WebXml.com.cn/") .setParam("mobileCode", "<![CDATA[13203389752]]>", true) .setParam("userID", "<![CDATA[]]>", false); result = client.send(false); result = soapXml(result, ""); log.error("出参:{}", result); } catch (Exception ex) { throw ex; } return result; } private String soapXml(String xml, String xpath) { // 处理返回的XML数据 return xml; } } ``` ### 注意事项 - 确保WSDL地址正确且可访问。 - 如果需要处理复杂的SOAP消息头,可以在`SoapClient`中设置自定义头信息。 - 使用日志记录工具(如`@Slf4j`)可以帮助调试SOAP请求和响应。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值