我有下面的 Azure Function c# 代码可以正常工作。
我调用 webservice 并将 xml 数据作为输入传递,但 Azure 函数得到了 json 数据。
如何在调用 web 服务时映射此 xml 数据并传递?
string Jsonbody = await req.Content.ReadAsStringAsync();
// I'm confused how to map this Jsonbody data to xml and pass to httpContent
var httpContent = new StringContent(Jsonbody, Encoding.UTF8, "text/xml");
HttpClient httpClient = new HttpClient();
string requestUri = "https://mydemo.com/myservice.asmx?listdata";
var byteArray = Encoding.ASCII.GetBytes("username:password");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
HttpResponseMessage response = await httpClient.PostAsync(requestUri, httpContent);
string result = await new StreamReader(response.Content.ReadAsStreamAsync().Result).ReadToEndAsync();
例如 - 函数应用输入 json -
{
"Name": "00141169",
"CurrencyCode": "EUR",
"Date": "2020-04-03",
}
映射到此 xml,该 xml 输入到将传递给的 web 服务httpContent
<?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>
<listdata xmlns="http://tempuri.org/">
<Name>KH001</Name>
<CurrencyCode>01/01/2018</CurrencyCode>
<Date>01/01/2020</Date>
</listdata>
</soap:Body>
</soap:Envelope>
就像在 Json 中一样,我们使用 C# 类使用 Json 序列化,然后分配值。我们可以用 Xml 做什么?
我有更多字段以上 3 个字段只是示例数据。
如果我直接从邮递员调用函数应用程序并将 xml 输入传递到正文中它工作正常。我的问题是如果函数应用程序输入是 json 如何将其映射到 xml 并通过。

