简体   繁体   English

ASP.NET Web服务参数类型

[英]ASP.NET web service parameter type

How to I control parameter type tag in ASP.NET web service? 如何在ASP.NET Web服务中控制参数类型标记? I get < xml>string< /xml> in one web application and < data>string< /data> in other... Is there a way to control this? 我在一个Web应用程序中获取<xml> string </ xml>,在其他Web中获取<data> string </ data> ...有没有办法控制它?

[WebMethod]
public bool TestFunction(string xml)
{
    //DO SOMETHING
    return true;
}

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <TestFunction xmlns="http://tempuri.org/">
      <xml>string</xml> //<data>string</data>
    </TestFunction>
  </soap:Body>
</soap:Envelope>

edit: I forgot to rename function 编辑:我忘了重命名功能

Any method is exposed using the parameter names you specify. 使用您指定的参数名称公开任何方法。 If you change your method to public bool TestFunction(string FooBar) , then the string will be in a <FooBar>string</FooBar> tag in the resulting XML. 如果将方法更改为public bool TestFunction(string FooBar) ,则字符串将位于生成的XML中的<FooBar>string</FooBar>标记中。

When you are using WCF you can change this behavior using Message Contracts or applying a MessageParameter to instruct the serializer to use an alternate name: 当您使用WCF时,您可以使用消息合同或应用MessageParameter来指示序列化程序使用备用名称来更改此行为:

public bool TestFunction([MessageParameter(Name="YourName")]string xml)

However, I don't know whether this also applies to ASP.Net web services. 但是,我不知道这是否也适用于ASP.Net Web服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM