Using SOAP web service object as a model in ASP.NET MVC 2

江枫思渺然 提交于 2019-12-24 04:02:13

问题


Good day!

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)
{
}

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


回答1:


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.



来源:https://stackoverflow.com/questions/4375515/using-soap-web-service-object-as-a-model-in-asp-net-mvc-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!