如何修改默认的SOAP请求?

问题描述 投票:0回答:1

所以我正在使用C#ASMX项目构建WS。我已经完成了,但是有人要我更改请求的值。需要更改的值是正文请求,其中它说“ request”,他们需要它说“ data”,是否有任何数据注释可以做到这一点?这是请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetData>
         <!--Optional:-->
         <tem:request(this is the word to replace)>
            <!--Optional:-->
            <tem:Param1></tem:Param1>
            <!--Optional:-->
            <tem:Param2></tem:Param2>
            <!--Optional:-->
            <tem:Param3></tem:Param3>
            <!--Optional:-->
            <tem:Param4></tem:Param4>
            <!--Optional:-->
            <tem:Param5></tem:Param5>
         </tem:request(this is the word to replace)>
      </tem:GetData>
   </soapenv:Body>
</soapenv:Envelope>

更新:WebMethod看起来像这样:

[WebMethod]
public GetDataResponse GetData(GetDataRequest request)
{
    //Do Something
}

和GetDataRequest看起来像:

public class GetDataRequest
{
    public string Param1 = String.Empty;
    public string Param2 = String.Empty;
    public string Param3 = String.Empty;
    public string Param4 = String.Empty;
    public string Param5 = String.Empty;
}

感谢您的帮助。

c# asmx
1个回答
0
投票

因此,在寻找答案之后,我进入了注释:[XmlRoot("data")]。像这样在类声明之前出现:

[XmlRoot("data")]
public class GetDataRequest
{
    public string Param1 = String.Empty;
    public string Param2 = String.Empty;
    public string Param3 = String.Empty;
    public string Param4 = String.Empty;
    public string Param5 = String.Empty;
}

使用此名称,您可以更改请求中显示的名称。

© www.soinside.com 2019 - 2024. All rights reserved.