Skip to content

Apache CXF使用soap1.2协议

Published:

Apache CXF默认创建的是soap1.1协议的,不支持一些新的规范

SOAP协议的主要版本有:

Apache CXF中如果要使用SOAP 1.2协议,需要用Factory来创建服务

使用factory创建服务

val url = "http://127.0.0.1:7001/service"
val factory = JaxWsServerFactoryBean()
factory.serviceClass = MyService::class.java
factory.address = url
factory.serviceBean = Main()

val bindingConfig = SoapBindingConfiguration()
bindingConfig.version = org.apache.cxf.binding.soap.Soap12.getInstance()
factory.bindingConfig = bindingConfig

factory.create()

指定命名空间

@WebService(targetNamespace = "http://tempuri.org/")
interface MyService {
    fun Hello(): String
}
@WebService(endpointInterface = "MyService",
    targetNamespace = "http://tempuri.org/",
    serviceName = "MyServiceService",
    portName = "MyServicePort")
class Main : MyService{
    override fun Hello(): String {
        return "Hello, World!"
    }
}

完整代码

@WebService(targetNamespace = "http://tempuri.org/")
interface MyService {
    fun Hello(): String
}
@WebService(endpointInterface = "MyService",
    targetNamespace = "http://tempuri.org/",
    serviceName = "MyServiceService",
    portName = "MyServicePort")
class Main : MyService{
    override fun Hello(): String {
        return "Hello, World!"
    }
}

fun main(args: Array<String>) {
    val url = "http://127.0.0.1:7001/service"
    val factory = JaxWsServerFactoryBean()
    factory.serviceClass = MyService::class.java
    factory.address = url
    factory.serviceBean = Main()

    val bindingConfig = SoapBindingConfiguration()
    bindingConfig.version = org.apache.cxf.binding.soap.Soap12.getInstance()
    factory.bindingConfig = bindingConfig

    factory.create()
}

Previous Post
java/kotlin webservice客户端
Next Post
Apache CXF Hello World