Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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();

                }
            }


        }
Posted
Updated 5-Oct-18 7:00am

1 solution

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.
C#
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.
C#
MyData instanceOfData = new MyData
{
   mid = "69bcdcdafdse474eaf8b201803151343",
   timee = "2018-06-01T13:47:23.00",
   etc, etc, etc.
};

3. Serialize your object for the web service
C#
 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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900