我可以在C#WebMethod中更改参数名称吗? [英] Can I change a parameter name in a C# WebMethod?
本文介绍了我可以在C#WebMethod中更改参数名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C#WebMethod是否可以接受与其客户端发送的参数名称不同的参数名称?
Is it possible for a C# WebMethod to accept a different parameter name than its client sends?
例如,假设有一个客户发送此消息:
For example, given a client sending this message:
<?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>
<GetStatus xmlns="http://example.com/">
<Arg1>5</Arg1>
<Arg2>3</Arg2>
</GetStatus>
</soap:Body>
</soap:Envelope>
是否可以重写现有的WebMethod来容纳不同的参数名称?像这样吗?
Can the existing WebMethod be rewritten to accommodate different argument names? Something like this?
[WebMethod]
public string GetStatus(
[MessageParameter(Name = "Arg1")] string orderId,
[MessageParameter(Name = "Arg2")] string typeId)
推荐答案
您应该可以使用XmlElementAttribute来做到这一点,例如:
You should be able to do it with the XmlElementAttribute, e.g:
[WebMethod]
public string GetStatus(
[XmlElementAttribute(ElementName = "Arg1")] string orderId,
[XmlElementAttribute(ElementName = "Arg2")] string typeId)
这篇关于我可以在C#WebMethod中更改参数名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文