using XMLElement as WebMethod param

R

Raj

Please observe the code snippet:

POST http://localhost/KRA/ASPDOTNET/DataService.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type:
application/soap+xml;charset=UTF-8;action="http://localhost/ASPDOTNET/XmlDataProcessing"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost
Content-Length: 472

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ihut="http://localhost/ASPDOTNET">
<soap:Header>
<ihut:UserCredentials>
<ihut:Username>dseadmin</ihut:Username>
<ihut:password>adsfasdf</ihut:password>
</ihut:UserCredentials>
</soap:Header>
<soap:Body>
<ihut:XmlDataProcessing>
<ihut:argstring>
<x>y</x>
</ihut:argstring>
</ihut:XmlDataProcessing>
</soap:Body>
</soap:Envelope>

I am getting error message as:
Data at the root level is invalid. Line 1, position 1

I need to pass <x>y</x> instead of y.

The web method is declared as XmlDataProcessing(XMLElement argstring)

Is there any workaround to fix this problem.

Thank you

Regards
Raj
 
M

Martin Honnen

Raj said:
Please observe the code snippet:

POST http://localhost/KRA/ASPDOTNET/DataService.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type:
application/soap+xml;charset=UTF-8;action="http://localhost/ASPDOTNET/XmlDataProcessing"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost
Content-Length: 472

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ihut="http://localhost/ASPDOTNET">
<soap:Header>
<ihut:UserCredentials>
<ihut:Username>dseadmin</ihut:Username>
<ihut:password>adsfasdf</ihut:password>
</ihut:UserCredentials>
</soap:Header>
<soap:Body>
<ihut:XmlDataProcessing>
<ihut:argstring>
<x>y</x>
</ihut:argstring>
</ihut:XmlDataProcessing>
</soap:Body>
</soap:Envelope>

I am getting error message as:
Data at the root level is invalid. Line 1, position 1

That sounds like an error message of an XML parser but you have not
shown any code using an XML parser respectively you have not explained
what exactly you do with C# when you get that error.
The code you show above is some XML preceded by some HTTP request
headers. How does your C# code look? How do you send above to your web
method?
One explanation for that error would be that the XML parser parses the
HTTP headers you have shown.
 
R

Raj

data sent in soap body:

<ihutidata
<autoip>meterserialnumber|service|location|circle|ip|signalstrength|modemdatetime</autoip
<instant>meterserialnumber|service|location|circle|ip|insvol1|insvol3|inscur1|inscur3|insKW1|insKW3|insKVAR1|insKVAR3|insKVA1|insKVA3|insPF|freq|devdatetime|kwhacc|kvarhacc|kvahacc|forkwhacc|revkwhacc|forleadkvarh|forlagkvarh|revleadkvarh|revlagkvarh|forkvahaccu|revkvahacc|sigstrength|ihutigprstime</instant>
<cumulative>cum|cum</cumulative>
<powerfailure>meterserialnumber|offdatetime|ondatetime</powerfailure>
<tamper>meterserialnumber|starttime|duration|type</tamper>
<billingreset>bill|bill</billingreset>
</ihutidata>

public string xmldata(XmlElement xe)
{
XmlDocument xd = new XmlDocument();
xd.LoadXml(xe.InnerXml);

string autoip = string.Empty;
string instant = string.Empty;
string cumulative = string.Empty;
string pf = string.Empty;
string tamper = string.Empty;
string billingreset = string.Empty;

if(null!=xd.SelectSingleNode("ihutidata/autoip"))
autoip =
xd.SelectSingleNode("ihutidata/autoip").InnerText.Trim();

if(null!=xd.SelectSingleNode("ihutidata/instant"))
instant =
xd.SelectSingleNode("ihutidata/instant").InnerText.Trim();

if(null!=xd.SelectSingleNode("ihutidata/cumulative"))
cumulative =
xd.SelectSingleNode("ihutidata/cumulative").InnerText.Trim();

if(null!=xd.SelectSingleNode("ihutidata/powerfailure"))
pf =
xd.SelectSingleNode("ihutidata/powerfailure").InnerText.Trim();

if(null!=xd.SelectSingleNode("ihutidata/tamper"))
tamper =
xd.SelectSingleNode("ihutidata/tamper").InnerText.Trim();

if(null!=xd.SelectSingleNode("ihutidata/billingdata"))
billingreset =
xd.SelectSingleNode("ihutidata/billingdata").InnerText.Trim();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top