Link to home
Start Free TrialLog in
Avatar of IUSR
IUSR

asked on

WCF service with list array request

Hi,

i'm newbie in C# and web service but i need to read the soap service (xml format) and save it to a SQL tables (dataset)...

here's my client's data:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pix="">
      <soapenv:Header/>
      <soapenv:Body>
            <tem:Request>
                  <pix:wsVersion>v1.2.1</pix:wsVersion>
                  <pix:cname>Testaccount</pix:cname>
                  <pix:sclass>sales</pix:sclass>
                  <pix:PO>PO12345</pix:PO>
                  <pix:method>AIR</pix:method>
                  <pix:product>
                        <pix:style>Abc1</pix:style>
                        <pix:qty>1</pix:qty>
                        <pix:price>1.00</pix:price>
                  </pix:product>
                  <pix:product>
                        <pix:style>Cde1</pix:style>
                        <pix:qty>2</pix:qty>
                        <pix:price>1.00</pix:price>
                  </pix:product>
            </tem:Request>
      </soapenv:Body>
</soapenv:Envelope>

I have 2 classes:
class order
            [MessageBodyMember(Order = 0)]
            public string wsVersion { get; set; }
            [MessageBodyMember(Order = 1)]
            public string cname { get; set; }
            [MessageBodyMember(Order = 2)]
            public string PO { get; set; }
            [MessageBodyMember(Order = 3)]
            public string method { get; set; }
            [MessageBodyMember(Order = 4)]
            [XmlArrayItem("oItems", IsNullable = false)]
            public Item[] Items { get; set; }
class Item
            [XmlElement(Order = 0)]
            public string style { get; set; }
            [XmlElement(Order = 1)]
            public int qty { get; set; }
            [XmlElement(Order = 2)]
            public double price { get; set; }

in service.svc.cs

wsVersion = httpUtility.HtmlEncode(request.wsVersion);
cname= httpUtility.HtmlEncode(request.cname);
PO= httpUtility.HtmlEncode(request.PO);
method= httpUtility.HtmlEncode(request.method);

items = new Item();
listItem = new List<Item>();
listItem.style = HttpUtility.HtmlEncode(request.item.style());  <---

i do not know how to read the xml element array, should i just use reader at the very beginning?
can someone give me a hint or something? should i not use httpUtility.HtmlEncode?...

thank you!
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Hi,

sorry,but I could not fully understand the question.

Are you developing a WCF service which should get the above SOAP structure?
Or are you consuming another service which returns the above elements?

Thanks for clarification,
Rainer
Avatar of IUSR
IUSR

ASKER

Hi Rainer,
yes, i'm developing a WCF service, the client will send me the SOAP structure request and i reply with order number.
but i'm having problem reading the request, i can read the single nodes without any issue but the product array is difficult and i do not know how many items will be.
-i tried xml deserialize the whole request but encounter the "Object reference not set to an instance of an object."
-trying the FastMember from NuGet Packages but the red wavy underline showing my array object is unknown...

any suggestion on how to properly read xml request with array items is greatly appreciate...
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.