在Web服务中接收soap对象

时间:2015-12-25 07:50:52

标签: c# web-services soap

我有一个网络服务:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Payer : System.Web.Services.WebService
{
    [WebMethod]
    public string MakePayment(Payment request)
    {
        try
        {
            return string.Format("payment number: {0}", request.PaymentNumber + request.Currency);
        }
        catch (Exception e)
        {
            return string.Format("Error: {0}", e.Message);
        }
    }
}

课程Payment

[XmlRoot(Namespace = "http://example.org/MyInterface")]
public class Payment
{
    [XmlNamespaceDeclarations]
    public XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();

    public Payment()
    {
        xmlns.Add("a", "http://example.org/MyInterface");
    }

    [XmlElement(Namespace = "http://example.org/MyInterface")]
    public string PaymentNumber { get; set; }

    [XmlElement(Namespace = "http://example.org/MyInterface")]
    public string Currency { get; set; }
}

我需要通过xml模板接收soap对象:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <Payment xmlns="http://tempuri.org/">
      <request xmlns:a="http://example.org/MyInterface" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:PaymentNumber></a:PaymentNumber>
        <a:Currency></a:Currency>
      </request>
    </Payment>
  </s:Body>
</s:Envelope>

如何指定前缀&#34; a&#34;对于请求a:xlmnsa:PaymentNumbera:Currency

我尝试使用[XmlNamespaceDeclarations],但它不起作用。当我在示例中在网络浏览器中打开我的网络服务*.asmx时,我发现我的方法MakePayment不包含前缀a

我使用.NET 4.5.1

0 个答案:

没有答案