我可以一起使用SOAP Webservices和Spring MVC吗? [英] Can I use SOAP Webservices and Spring MVC together
问题描述
我有一个Spring MVC项目。我写了类似的代码
I have a Spring MVC project. I wrote a code something like
@Controller
@RequestMapping("CallBack")
@WebService(name = "NotificationToCP", targetNamespace = "http://SubscriptionEngine.ibm.com")
public class CallbackController {
@RequestMapping("")
@ResponseBody
@WebMethod(action = "notificationToCP")
@RequestWrapper(localName = "notificationToCP", targetNamespace = "http://SubscriptionEngine.ibm.com", className = "in.co.mobiz.airtelVAS.model.NotificationToCP_Type")
@ResponseWrapper(localName = "notificationToCPResponse", targetNamespace = "http://SubscriptionEngine.ibm.com", className = "in.co.mobiz.airtelVAS.model.NotificationToCPResponse")
public NotificationToCPResponse index(
@WebParam(name = "notificationRespDTO", targetNamespace = "") CPNotificationRespDTO notificationRespDTO) {
return new NotificationToCPResponse();
}
}
我可以一起使用Spring MVC + Webservices吗?我想要的只是作为一个接受SOAP请求并处理它的控制器。网址需要/ CallBack。我仍然像一个新手一样迷茫。上面的东西会起作用吗否则我该如何实现。
Can I use Spring MVC + Webservices together? What I want is just as a controller that accepts a SOAP request and process it. The url needs to be /CallBack. I'm still as a sort of confused being a Newbie. Will something like above work. Else how do I get it going.
推荐答案
我不会将Spring MVC和SOAP webservice(JAX-WS)混合在一起它们用于不同的目的。
I wouldn't mix Spring MVC and SOAP webservice (JAX-WS) together since they serve different purpose.
更好的做法是将业务操作封装在服务类中,并使用MVC控制器和JAX-WS公开它。例如:
Better practice is to encapsulate your business operation in a service class, and expose it using both MVC controller and JAX-WS. For example:
HelloService
HelloService
@Service
public class HelloService {
public String sayHello() {
return "hello world";
}
}
HelloController通过自动装配注入HelloService引用。这是标准的Spring MVC控制器,它调用服务并将结果作为模型传递给视图(例如:hello.jsp视图)
HelloController has HelloService reference injected via autowiring. This is standard Spring MVC controller that invoke the service and pass the result as a model to a view (eg: hello.jsp view)
@Controller
@RequestMapping("/hello")
public class HelloController {
@Autowired private HelloService helloService;
@RequestMapping(method = RequestMethod.GET)
public String get(Model model) {
model.addAttribute("message", helloService.sayHello());
return "hello";
}
}
JAX-WS端点也调用相同的服务。区别在于服务作为SOAP Web服务公开
A JAX-WS endpoint also invoke the same service. The difference is the service is exposed as a SOAP web service
@WebService(serviceName="HelloService")
public class HelloServiceEndpoint {
@Autowired private HelloService helloService;
@WebMethod
public String sayHello() {
return helloService.sayHello();
}
}
请注意,上面的JAX-WS样式的Web服务不是'保证自动处理所有Spring部署,特别是如果部署在非Java EE环境(tomcat)上。可能需要进行其他设置。
Note that JAX-WS style web service above isn't guaranteed to automatically work on all Spring deployment, especially if deployed on non Java EE environment (tomcat). Additional setup might be required.
这篇关于我可以一起使用SOAP Webservices和Spring MVC吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!