How to read xmlString passed via SOAP to Web Service ASMX

Posted on 2011-10-31
Medium Priority
Last Modified: 2012-05-12
I am trying to send a SOAP message (which contains my xmlString) to my Web Service.
The Web Service needs to read my xmlString, do something, then return something.
I am having problems getting my Web Service ASMX to read the SOAP xmlString.

This is my Web Service info

POST /myWebService.asmx HTTP/1.1
Host:   mywebsite.com()
Content-Type: text/xml; charset=utf-8
        Content(-Length) : length()
SOAPAction: http://mywebsite.com/Pets

<?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/">
    <Pets xmlns="http://website.com/">

This is the SOAP Xml that I am sending to the Web Service

<?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/">
   <Pets xmlns="http://mywebsite.com/">
        <?xml version="1.0" encoding="utf-8"?>
        <myPet xmlns="http://mywebsite.com/">

This is my Web Service ASMX info

Public Function Pets(ByVal xmlString As String) As String

    ??? How do I read the passed xmlString & parse our the values Animal, Breed, Name, etc ???

    ' I thought this might work....
    Dim sr as New StringReader(xmlString)
    Dim xmlReader as New XmlTextReader(sr)

    Dim curAnimal as string = ""
    xmlReader.WhitespaceHandling = WhitespaceHandlinig.None
    While xmlReader.Read()
         if xmlReader.Name = "Animal" then
               curAnimal = xmlReader.ReadElementString("Animal")
         end if

    Dim strXMLStringResponse as string = "ok"
    Return strXMLStringResponse
End Function

Error: I am getting this error --> Server Error in '/' Application

I believe that the ASMX Web Service is not understanding the xmlString that I passed in my SOAP message

Any ideas ??

Question by:MikeCombe
  • 2

Accepted Solution

anugu earned 1000 total points
ID: 37059381

You can create a class named Pet like:

public class Pet

   Public Pet()

   public String Name { get; set; }
   public String Animal { get; set; }
   public String Breed { get; set; }

And than use XmlSerializer to create an object from the string like:

XmlSerializer ser = new XmlSerializer(typeof(Pet))

ser.Deserialize( ....... ) use an xmlreader and a stringbuilder here.

See http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx for more info about the XmlSerializer...

Note: the class must have a parameterless constructor and all the properties must be public and settable...

You can also do this with a list of pets etc....


Author Comment

ID: 37059434
no....that is the wrong direction.
I want to pass an xmlString via SOAP to my Web Service.
I want the Web Service to parse the xmlString, then return an xmlStringReponse.


Expert Comment

ID: 37060909
With the code above you can 'parse' your xmlString into an object (Deserialize it) in your webservice. That was an answer to your question " ??? How do I read the passed xmlString & parse our the values Animal, Breed, Name, etc ???"

That way you will be able to do things like :

if (pet.Animal == "Dog")


As for your exception, the xmlString tag in the delivered soap message is missing.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question