<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xxx="http://tempuri.org/xxx.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<sayHello xmlns="http://service.mycode.com/">
<uname>123456</uname>
</sayHello>
</soapenv:Body>
</soapenv:Envelope>
<!-- sayHello是方法名 uname 是参数名 123456 是要传的值 xmlns="http://service.mycode.com/"是后台配置的 targetNamespace = "http://service.mycode.com/"-->
<!-- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<sayHello xmlns="http://service.mycode.com/">
<uname>青山隐隐水迢迢</uname>
</sayHello>
</soap:Body>
</soap:Envelope> -->
后台代码
import com.mycode.service.NetbarServices;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.el.ELManager;
import javax.xml.ws.Endpoint;
@Configuration
public class CxfConfig {
@Autowired
private Bus bus;
@Autowired
private NetbarServices netbarServices;
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus,netbarServices);
//明确(暴露)该服务的接口地址,防止nginx代理时丢失端口(也可以服务器开通该端口)
// endpoint.setPublishedEndpointUrl("127.0.0.1:701/webservice/pushProperData?wsdl");
// endpoint.getInInterceptors().add(new AuthInterceptor());
endpoint.publish("/NetbarServices");//接口发布在 /NetbarServices 目录下
return endpoint;
}
}
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
* 网吧web services 接口
* @author xiaojf 2017/7/24 21:35
*/
@WebService// 命名空间,一般是接口的包名倒序
public interface NetbarServices {
@WebMethod
String sayHello(@WebParam(name = "uname", targetNamespace = "http://service.mycode.com/") String uname);
}
import javax.jws.WebParam;
import javax.jws.WebService;
import org.springframework.stereotype.Component;
/**
* 网吧web services 接口实现
* @author xiaojf 2017/7/24 21:38
*/
@WebService(serviceName = "NetbarServices"//服务名
,targetNamespace = "http://service.mycode.com/"//包名倒序,并且和接口定义保持一致
,endpointInterface = "com.mycode.service.NetbarServices")//包名
@Component
public class NetbarServicesImpl implements NetbarServices {
@Override
public String sayHello(String uname) {
System.out.println("vdsvfsvdsvdsvdsvdsv");
return "hello , "+ uname;
}
}
application.properties
#开发环境
server.port=701
cxf.path=/webservice