在ASP.NET MVC 2中将SOAP Web服务对象用作模型 [英] Using SOAP web service object as a model in ASP.NET MVC 2

查看:84
本文介绍了在ASP.NET MVC 2中将SOAP Web服务对象用作模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

我已经有需要通过控制器操作调用的Web服务.我的Web服务方法如下:MyWebServiceMethod(MyWebServiceClass param1).是否可以在MVC中直接使用MyWebServiceClass,我的意思是附加DataAnnotations(Web服务类是局部的)以进行验证并创建如下操作:

I've existing web service I need to call from controller's action. My web service method looks like this: MyWebServiceMethod(MyWebServiceClass param1). Is it possible to use MyWebServiceClass directly in MVC, I mean attach DataAnnotations (the web services classes are partial) for validation and create action like this:

[HttpPost]
public ActionResult MyAction(MyWebServiceClass param1)
{
}

还是应该在绑定\验证后创建单独的ViewModel类并将数据复制到MyWebServiceClass实例?

Or I should create separate ViewModel class and copy data to MyWebServiceClass instance after binding\validation?

推荐答案

您绝对应该创建一个视图模型,该模型适合要发布到此控制器操作的给定视图的需求.并且,一旦您检查了模型状态是否有效,就可以使用 AutoMapper 在此视图模型和您的Web服务期望的实际模型类.

You should definitely create a view model which is tailored to the needs of the given view which is posting to this controller action. And once you've checked that the model state is valid you could use AutoMapper to convert between this view model and the actual model class that your web service is expecting.

这篇关于在ASP.NET MVC 2中将SOAP Web服务对象用作模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆