gpt4 book ai didi

web-services - 如何更改 .asmx 响应中的元素名称?

转载 作者:行者123 更新时间:2023-12-02 01:49:28 25 4
gpt4 key购买 nike

网络服务返回如下所示的 xml。消费客户端期望

代码:

[WebMethod]
public MyResponseObj MyMethod(MyRequestObj Request)
{
try
{
MyResponseObj response = new MyResponseObj();
response.Message = "test";
response.Status = Status.success;
return response;
}
catch(Exception ex)
{
throw;
}
}

实际响应:

<?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>
<MyMethodResponse xmlns="MyNameSpace">
<MyMethodResult>
<Status>success or failure</Status>
<Message>string</Message>
</MyMethodResult>
</MyMethodResponse>
</soap:Body>
</soap:Envelope>

预期响应

<?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>
<MyMethodResponse xmlns="MyNameSpace">
**<Response>**
<Status>success or failure</Status>
<Message>string</Message>
**</Response>**
</MyMethodResponse>
</soap:Body>
</soap:Envelope>

最佳答案

我通过使用 [XmlRoot("Response")] 装饰 MyResponseObj 类来使其工作

[XmlRoot("Response")]
public partial class MyResponseObj
{

}

关于web-services - 如何更改 .asmx 响应中的元素名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23742023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com