gpt4 book ai didi

asp.net - 需要网络服务的帮助

转载 作者:行者123 更新时间:2023-12-01 05:05:11 24 4
gpt4 key购买 nike

我生成了一个简单的 Web 服务。其中,当我调用服务时,输出将显示不同。代码是...

public class DistictName
{
public string DisticName { get; set; }
}
public class Distict
{
public string DistictName { get; set; }
public List<DistictName> DistName { get; set; }
}

[WebMethod]
public Distict DistictNameByState(String StateName)
{
Distict DName = new Distict();
DName.DistName = new List<DistictName>();
DataTable dtDistictName = clsDefault.getproduct("sp_getDistictName", "Distict", StateName.ToString());

for (int i = 0; i < dtDistictName.Rows.Count; i++)
{
DName.DistName.Add(new DistictName() { DisticName = dtDistictName.Rows[i]["Distict_Name"].ToString() });
}
return DName;
}

当我输入州名称时,例如古吉拉特邦和地区名称将显示在 SoapUI 编辑器上,例如...
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<DistictNameByStateResponse xmlns="http://tempuri.org/">
<DistictNameByStateResult>
<DistName>
<DistictName>
<DisticName>Ahmedabad</DisticName>
</DistictName>
<DistictName>
<DisticName>Amreli</DisticName>
</DistictName>
<DistictName>
<DisticName>Anand</DisticName>
</DistictName>
<DistictName>
<DisticName>Aravalli</DisticName>
</DistictName>
<DistictName>
<DisticName>Banaskantha</DisticName>
</DistictName>
<DistictName>
<DisticName>Bharuch</DisticName>
</DistictName>
<DistictName>
<DisticName>Bhavnagar</DisticName>
</DistictName>
</DistName>
</DistictNameByStateResult>
</DistictNameByStateResponse>
</soap:Body>
</soap:Envelope>

但我需要这种类型的输出...
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<DistictNameByStateResponse xmlns="http://tempuri.org/">
<DistictNameByStateResult>
<DistName>
<DisticName>Ahmedabad</DisticName>
<DisticName>Amreli</DisticName>
<DisticName>Anand</DisticName>
<DisticName>Aravalli</DisticName>
<DisticName>Banaskantha</DisticName>
<DisticName>Bharuch</DisticName>
<DisticName>Bhavnagar</DisticName>
</DistName>
</DistictNameByStateResult>
</DistictNameByStateResponse>
</soap:Body>
</soap:Envelope>

怎么做?我可以在我的代码中更改什么...?

最佳答案

您需要返回 List<Distict> .所以你需要使用以下代码。

public class Distict
{
public string DistictName { get; set; }
}

[WebMethod]
public List<Distict> DistictNameByState(String StateName)
{
List<Distict> DName = new List<Distict>();
DataTable dtDistictName = clsDefault.getproduct("sp_getDistictName", "Distict", StateName.ToString());

for (int i = 0; i < dtDistictName.Rows.Count; i++)
{
Distict dst = new Distict();
dst.DisticName = dtDistictName.Rows[i]["Distict_Name"].ToString() ;
DName.Add(dst);
}
return DName;
}

关于asp.net - 需要网络服务的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29575781/

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