postman调用webservice接口
写webservice服务
编写service服务,并用@WebService (targetNamespace = “http://服务地址/Sheet”, endpointInterface=“webService接口所在包地址”, serviceName = “服务名称”)
@Slf4j
@WebService (targetNamespace = "http://服务地址/Sheet",
endpointInterface = "webService接口所在包地址",
serviceName = "Sheet(服务名)")
@Component
public class WebServiceImpl implements WebService{
@Override
public String Sheet(){
log.info("进来了……");
}
}
webservice接口配置
@WebService (name = "Sheet(别名)", targetNamespace = "http://服务地址/Sheet")
public interface WebService{
@WebMethod
String Sheet(@WebParam (name="参数名" , targetNamespace = "http://服务地址/Sheet" ) String sheetType(参数名),
@WebParam (name="参数名" , targetNamespace = "http://服务地址/Sheet" ) String serviceType(参数名));
}
配置WebServiceConfig
@Configuration
public class WSConfig {
@Autowired
@Qualifier(Bus.DEFAULT_BUS_ID)
Bus bus;
@Autowired
WebService sheet;
private static String WSDL = "wsdl/WS.wsdl";//(协议)放在resource下
/**
* 端口 路径 注入
*
* @return ServletRegistrationBean
*/
@Bean
public ServletRegistrationBean disServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/WS/*");
}
/**
* 拦截方法注入
*
* @return
*/
@Bean
public Endpoint endpoints() {
EndpointImpl endpoint = new EndpointImpl(bus, sheet);
ClassPathResource classPathResource = new ClassPathResource(WSDL);
endpoint.setWsdlLocation(classPathResource.getPath());
endpoint.publish("/Sheet");
return endpoint;
}
}
协议
<s0:definitions xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="http://服务地址/Sheet" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="" name="ForBomcCooperationSheetDefinitions" targetNamespace="http://服务地址/Sheet">
<s0:types>
<xs:schema xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="http://服务地址/Sheet" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://服务地址/Sheet">
<xs:element name="replyWorkSheet">
<xs:complexType>
<xs:sequence>
<xs:element name="arg0" type="xs:string"/>
<xs:element name="arg1" type="xs:string"/>
<xs:element name="arg2" type="xs:string"/>
<xs:element name="arg3" type="xs:string"/>
<xs:element name="arg4" type="xs:string"/>
<xs:element name="arg5" type="xs:string"/>
<xs:element name="arg6" type="xs:string"/>
<xs:element name="arg7" type="xs:string"/>
<xs:element name="arg8" type="xs:string"/>
<xs:element name="arg9" type="xs:string"/>
<xs:element name="arg10" type="xs:string"/>
<xs:element name="arg11" type="xs:string"/>
<xs:element name="arg12" type="xs:string"/>
<xs:element name="arg13" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SheetResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="isAlive">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="isAliveResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</s0:types>
<s0:message name="SheetResponse">
<s0:part element="s1:SheetResponse" name="parameters"/>
</s0:message>
<s0:message name="Sheet">
<s0:part element="s1:Sheet" name="parameters"/>
</s0:message>
<s0:message name="SheetResponse">
<s0:part element="s1:SheetResponse" name="parameters"/>
</s0:message>
<s0:message name="isAlive">
<s0:part element="s1:isAlive" name="parameters"/>
</s0:message>
<s0:message name="isAliveResponse">
<s0:part element="s1:isAliveResponse" name="parameters"/>
</s0:message>
<s0:portType name="Sheet">
<s0:operation name="Sheet" parameterOrder="parameters">
<s0:input message="s1:Sheet"/>
<s0:output message="s1:SheetResponse"/>
</s0:operation>
<s0:operation name="isAlive" parameterOrder="parameters">
<s0:input message="s1:isAlive"/>
<s0:output message="s1:isAliveResponse"/>
</s0:operation>
</s0:portType>
<s0:binding name="CooperationSheetSoapBinding" type="s1:Sheet">
<s2:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<s0:operation name="Sheet">
<s2:operation soapAction="" style="document"/>
<s0:input>
<s2:body parts="parameters" use="literal"/>
</s0:input>
<s0:output>
<s2:body parts="parameters" use="literal"/>
</s0:output>
</s0:operation>
<s0:operation name="isAlive">
<s2:operation soapAction="" style="document"/>
<s0:input>
<s2:body parts="parameters" use="literal"/>
</s0:input>
<s0:output>
<s2:body parts="parameters" use="literal"/>
</s0:output>
</s0:operation>
</s0:binding>
<s0:service name="CooperationSheet">
<s0:port binding="s1:CooperationSheetSoapBinding" name="SheetSoapPort">
<s2:address location="http://ip:端口/CRMWS/Sheet"/>
</s0:port>
</s0:service>
</s0:definitions>
编写controller 给外部提供http调用
@GetMapping("……")
public String test(@RequestParam("url") String url,@RequestParam("met") String met…… ) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(url);
Object[] objects = new Object[0];
objects = client.invoke(method,参数……);
log.info("==================== 反馈数据 [ {} ]",objects);
}
postman GET调用 加上参数,直接send OK