是否可以对MVC绑定soap请求进行建模? [英] Is it possible to model bind a soap request with mvc?
问题描述
客户端具有一项服务,该服务发出我们需要通过.Net MVC4项目接收的xml soap格式的请求.请求的格式为:
A client has a service that sends out xml soap formatted requests that we need to receive via our .Net MVC4 project. A request would be in the format:
<?xml version="1.0" encoding="utf-8"?>
<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>
<ReceiveStatusUpdate xmlns="http://test.com">
<StatusUpdate>
<Reference>214563</Reference>
<ThirdPartyReference>YOUR-REFERENCE</ThirdPartyReference>
<Status>Pending</Status>
</StatusUpdate>
</ReceiveStatusUpdate>
</soap:Body>
</soap:Envelope>
我想知道接收和解析此请求的最佳方法是什么?
I'm wondering what would be the best way to receive and parse this request?
推荐答案
最简单的方法是使用老式的asmx Web服务.
The easiest way to achieve this is to use an old-fashioned asmx web service.
通过Web API进行公开将需要大量工作,因为它不支持现成的SOAP绑定.
Exposing via Web API would require considerable work as it does not support SOAP binding out of the box.
您可以使用WCF服务,但是它们配置起来很麻烦并且很耗时,这是为其灵活性付出的代价.
You could use a WCF service, but they can be fiddly and time consuming to configure, which is the price to pay for their flexibility.
简而言之,如果只需要支持SOAP绑定,请使用为该工作而设计的工具-asmx Web服务.
In short, if you only need to support SOAP bindings, use the tool that was made for that job - asmx web services.
只需向Web服务(ASMX)类型的MVC项目中添加一个新项目,如下所示(显然,您的StatusUpdate类将在单独的文件中定义).
Just add a new item to your MVC project of type Web Service (ASMX), example shown below (you'd obviously have your StatusUpdate class defined in a separate file).
/// <summary>
/// Summary description for StatusWebService
/// </summary>
[WebService(Namespace = "http://test.com")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class StatusWebService : System.Web.Services.WebService
{
[WebMethod]
public void ReceiveStatusUpdate(StatusUpdate StatusUpdate)
{
//Do whatever needs to be done with the status update
}
}
public class StatusUpdate
{
public string Reference { get; set; }
public string ThirdPartyReference { get; set; }
public string Status { get; set; }
}
这篇关于是否可以对MVC绑定soap请求进行建模?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!