如何一次发送多个请求 [英] How to send several requests in one time

查看:66
本文介绍了如何一次发送多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧我们要做一个在c#web服务中发送工作单并接收响应的项目​​,但我需要帮助因为我想要获取几个数据然后将其发送到Web服务但我不知道如何这样做



我尝试了什么:



<$ p $使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;

namespace ConsoleApplication1
{
class program
{
static void Main(string [] args)
{
myserv。 webService1 ss = new myserv.webService1();
string mid =69bcdcdafdse474eaf8b201803151343;
string timee =2018-06-01T13:47:23.00;
string user =testuser;
string userfunc =wmsintegration;
string req =importworkorder;
string site =de01;
string workord =DSIP1804060004321;
string worktyp =allocate;
string act =add;
string supp =;
string id =201804060955000002;
string sku =pc001234;
string desc =asprin;
string batch =testc7e8f04267;
string exdate =20221214;
string pdcode =;
string serial =;
string quan =5;
string clid =ukcl001234;
string ordid =pon2018005;
string cuscat =art23;
string channel =humvo;

string request =(@
< messageid>+ mid + @< / messageid>
< messageversion> 1.0< / messageversion>
< createdtimestamp>+ timee + @< / createdtimestamp>
< username>+ user + @< / username>
< userfunction>+ userfunc + @< ; / userfunction>
< requesttype>+ req + @< / requesttype>
< site>+ site + @< / site>
< workorder> + workord + @< / workorder>
< datetime>+ timee + @< / datetime>
< workordertype>+ worktyp + @< / workordertype>
< action>+ act + @< / action>
< supplement>+ supp + @< / supplement>
< ID>+ id + @ < / ID>
< sku>+ sku + @< / sku>
< description>+ desc + @< / description>
< batch>+ batch + @< / batch>
< expirydate>+ exdate + @< / expirydate>
< productcode>< / productcode>
< serialnumber>< / serialnumber>
< requiredquantity>+ quan + @< / requiredquantity>
< clientid>+ clid + @< / clientid>
< orderid>+ ordid + @< / orderid>
< customercategory>+ cuscat + @< / customercategory>
< channelvalidate>+ channel + @< / channelvalidate>
< channeldecommission>+ channel + @< / channeldecommission>
< supplement>< / supplement>);

Console.WriteLine(发送请求:::::::+请求);



字符串响应= ss.import(mid,timee,user,userfunc,req);

Console.WriteLine(response :::::::+响应);
Console.ReadKey();

}
}


}

解决方案

在较高级别,您需要在将XML数据提交到Web服务之前序列化它。

有几个步骤可以到那里。

1.创建一个类来定义你的数据。

  public   class  MyData 

[XmlElement(ElementName = messageid)]
string mid { get ; set ;}
[XmlElement(ElementName = createdtimestamp)]
string timee {获取; 设置;}
等等,



2.创建对象的实例并设置属性。

 MyData instanceOfData =  new  MyData 
{
mid = 69bcdcdafdse474eaf8b201803151343
timee = 2018-06-01T13:47:23.00
等等,等等。
};



3.为Web服务序列化对象

 XmlSerializer serializer =  new  XmlSerializer( typeof运算(instanceOfData)); 
string xml = ;
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false ;

使用 var sww = new StringWriter())
{
使用(XmlWriter writer = XmlWriter.Create(sww,settings))
{
serializer.Serialize(writer,instanceOfData);
xml = sww.ToString();
}
}

Console.WriteLine( 发送请求: :::::: + xml);


well guys I am going to do a project which send work order in c# web service and receive response ,but I need help cause I want to take several data then send it to the web service but I don't know how to do it

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            myserv.webService1 ss = new myserv.webService1();
                    string mid = "69bcdcdafdse474eaf8b201803151343";
                    string timee = "2018-06-01T13:47:23.00";
                    string user = "testuser";
                    string userfunc = "wmsintegration";
                    string req = "importworkorder";
                    string site = "de01";
                    string workord = "DSIP1804060004321";
                    string worktyp = "dispense";
                    string act = "add";
                    string supp = "";
                    string id = "201804060955000002";
                    string sku = "pc001234";
                    string desc = "asprin";
                    string batch = "testc7e8f04267";
                    string exdate = "20221214";
                    string pdcode = "";
                    string serial = "";
                    string quan = "5";
                    string clid = "ukcl001234";
                    string ordid = "pon2018005";
                    string cuscat = "art23";
                    string channel = "humvo";

                    string request = (@"
           <messageid>" + mid + @"</messageid>
           <messageversion>1.0</messageversion>
           <createdtimestamp>" + timee + @"</createdtimestamp>
           <username>" + user + @"</username>
           <userfunction>" + userfunc + @"</userfunction>
           <requesttype>" + req + @"</requesttype>
           <site>" + site + @"</site>
           <workorder>" + workord + @"</workorder>
           <datetime>" + timee + @"</datetime>
           <workordertype>" + worktyp + @"</workordertype>
           <action>" + act + @"</action>
           <supplement>" + supp + @"</supplement>
           <ID>" + id + @"</ID>
           <sku>" + sku + @"</sku>
           <description>" + desc + @"</description>
           <batch>" + batch + @"</batch>
           <expirydate>" + exdate + @"</expirydate>
           <productcode></productcode>
           <serialnumber></serialnumber>
           <requiredquantity>" + quan + @"</requiredquantity>
           <clientid>" + clid + @"</clientid>
           <orderid>" + ordid + @"</orderid>
           <customercategory>" + cuscat + @"</customercategory>
           <channelvalidate>" + channel + @"</channelvalidate>
           <channeldecommission>" + channel + @"</channeldecommission>
           <supplement></supplement>");

                    Console.WriteLine("sending request:::::::" + request);
                    


                    string response = ss.import(mid, timee, user, userfunc, req);

                    Console.WriteLine("response:::::::" + response);
                    Console.ReadKey();

                }
            }


        }

解决方案

At a high level, you need to serialize your XML data before you submit it to your web service.
There are a couple of steps to get there.
1. Create a class to define your data.

public class MyData
(
    [XmlElement(ElementName="messageid")]
    string mid {get;set;}
    [XmlElement(ElementName="createdtimestamp")]
    string timee {get;set;}
    etc, etc,

)


2. Create an instance of your object and set the properties.

MyData instanceOfData = new MyData
{
   mid = "69bcdcdafdse474eaf8b201803151343",
   timee = "2018-06-01T13:47:23.00",
   etc, etc, etc.
};


3. Serialize your object for the web service

 XmlSerializer serializer = new XmlSerializer(typeof(instanceOfData));
 string xml = "";
 XmlWriterSettings settings = new XmlWriterSettings();
 settings.OmitXmlDeclaration = false;

 using (var sww = new StringWriter())
 {
     using (XmlWriter writer = XmlWriter.Create(sww, settings))
     {
         serializer.Serialize(writer, instanceOfData);
         xml = sww.ToString();
     }
 }

Console.WriteLine("sending request:::::::" + xml);


这篇关于如何一次发送多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆