How to read xmlString passed via SOAP to Web Service ASMX

Posted on 2011-10-31
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
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 ??

Question by:MikeCombe
    LVL 2

    Accepted Solution


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


    Author Comment

    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.

    LVL 2

    Expert Comment

    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

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now