How to read xmlString passed via SOAP to Web Service ASMX

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
Content-Type: text/xml; charset=utf-8
        Content(-Length) : length()

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
    <Pets xmlns="">

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

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
   <Pets xmlns="">
        <?xml version="1.0" encoding="utf-8"?>
        <myPet xmlns="">

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 ??

Who is Participating?

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 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....

MikeCombeAuthor Commented:
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.

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.