Testing the web services .Net
Testing a web service is checking whether the .asmx file we create using visual studio.net is bug free and without any errors. We test the .asmx file and then we upload it on to the web server.
Before we start with test with web service, we should note that a web service does not have a interface. To over come this, .Net CLR creates a small site that enables us to test each method of a web service.
After we create the web service, we press F5 to build and run the web service. If successful, internet explorer will come up displaying the page containing list of the methods as well as a link to the Service Description as shown in below figure.
The Service Description link (shown in the top part of the picture) provides a description of all the methods, such as the number of parameters and their data types, the sequence of the parameters, and the return value of the methods exposed by the Web service.
In this case, this page displays the methods of the WebService, HelloWorld and warning to the effect that it uses the default namespace. After you decide to make the WebService available to others on the Internet, you should change the namespace to something like http://yourserver.com/ (where your Server is the name of the Web Server where the code resides).
By clicking on a method name, HelloWorld, we can see information about this particular method. This information includes the format of the SOAP request message it expects as well as the format of the SOAP response message it will send, and also provides a Web Form to test the Web service. A SOAP request message is expected by the Web service.
Recall that this is the message the client will pass to the Web service to indicate that it wants to invoke the HelloWorld() method.
The SOAP messages which travel from the client to the web service and back can be categorized as
1.SOAP request message 2.SOAP response message
Demystifying the SOAP message
SOAP Request message
SOAP documents are constructed with XML. Now we will go little deep into the SOAP document. All SOAP messages must adhere to a basic structure, which identifies the messages with XML namespaces. An XML namespace provides a mechanism to identify XML data types, as well as qualify both your element and attribute names. The XML namespace declarations are specified with the xml ns prefix.
XML namespaces enable us to distinguish between element names to avoid name collisions of elements that use the same name. At the start of a SOAP message, we should include a URL that references an XML schema that will define the structure of your message.
Although not required, we should point to a valid XML schema within a SOAP envelope. You can think of the Envelope tag as the root element of a SOAP message, specified with the
Change the fig and show with SOAP request/response documents with helloworld service.
Note that the SOAP Body will need to contain first an element named
From the above code we can make out that the child element of the
SOAP response message
The SOAP response message, which is passed back from the Web service to the invoking client, specifies the return value of the HelloWorld() method:
In this article, we have seen what SOAP is, and how SOAP messages are formatted to invoke Web services.