我刚开始使用Webservice。我向外部公司实现了soap Post操作。工作得很好。我现在想开始创造我自己的,让人们与我们互动。我已经创建了基本的添加服务,如所有教程等。
现在,我想要创建一个服务,您可以下订单。目前,我只是用PO作为文件名将订单写到文本文件中。测试工作只提交一个项目给它。但我想让他们把电话里的多个项目传递出去。这是我现在得到的。
c#
public struct OrderSystem
{
public string ResultMsg;
}
[WebMethod(MessageName = "Submit Order", Description = "Submit Order")]
public OrderSystem Order(string Custnr,string POnr, string[] Item , int[] qty)
{
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(@"C:\Users\Public\TestFolder\"+POnr+".txt"))
{
file.WriteLine(Custnr);
file.WriteLine(POnr);
for (int i =0; i< Item.Length; i++)
{
file.WriteLine("LineItem" + i +Item[i] + " | "+qty[i]);
}
}
OrderSystem result;
result.ResultMsg = "Complete";
return (result);
}当前调用它的XML方式。对他们设计给我的电话不友好
POST /Orders.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Submit Order"
<?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>
<Submit_x0020_Order xmlns="http://tempuri.org/">
<Custnr>string</Custnr>
<POnr>string</POnr>
<Item>
<string>string</string>
<string>string</string>
</Item>
<qty>
<int>int</int>
<int>int</int>
</qty>
</Submit_x0020_Order>
</soap:Body>
</soap:Envelope>如何使xml调用文件查看。
POST /Orders.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Submit Order"
<?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>
<Submit_x0020_Order xmlns="http://tempuri.org/">
<Custnr>000223</Custnr>
<POnr>988590</POnr>
<ItemList>
<Item>
<ItemNr>1</Item>
<Item>ABC123</Item>
<Qty>2</Qty>
</Item>
<Item>
<ItemNr>2</Item>
<Item>ASC123</Item>
<Qty>45</Qty>
</Item>
<Item>
<ItemNr>3</Item>
<Item>XYZKKF</Item>
<Qty>4</Qty>
</Item>
<Item>
<ItemNr>4</Item>
<Item>FGH789</Item>
<Qty>6</Qty>
</Item>
</ItemList>
</Submit_x0020_Order>
</soap:Body>
</soap:Envelope>我怎样才能改变我的C#服务来处理这个XML文件。
谢谢你事先问好
发布于 2018-06-13 14:16:05
首先,不要在2018年使用ASMX创建新服务。是已经被废弃了几年。使用WCF或。
该解决方案适用于所有技术。只需创建一个类:
public class Item
{
public string ItemNr { get; set; }
public int Quantity { get; set; }
}让您的服务接受该类的列表。
https://stackoverflow.com/questions/50839399
复制相似问题