Showing posts with label SOAP. Show all posts
Showing posts with label SOAP. Show all posts

What is SOAP?

SOAP is an XML-based protocol for exchanging information between computers. Although SOAP can be used in a variety of messaging systems and can be delivered via a variety of transport protocols, the main focus of SOAP is Remote Procedure Calls (RPC) transported via HTTP. Like XML-RPC, SOAP is platform independent, and therefore enables diverse applications to communicate with one another.
To get a quick sense of SOAP, here is a sample SOAP request to a weather service (with the HTTP Headers omitted):

xmlns:SOAP-ENV="http://www.w3.org/2001/09/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">


10016



As you can see, the request is slightly more complicated than XML-RPC and makes use of both XML namespaces and XML Schemas. Much like XML-RPC, however, the body of the request specifies both a method name (getWeather), and a list of parameters (zipcode).
Here is a sample SOAP response from the weather service:

xmlns:SOAP-ENV="http://www.w3.org/2001/09/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

xmlns:ns1="urn:examples:weatherservice"
SOAP-ENV:encodingStyle="http://www.w3.org/2001/09/soap-encoding">
*65
*
*

*
The response indicates a single integer return value (the current temperature).
The World Wide Web Consortium (W3C) is in the process of creating a SOAP standard. The latest working draft is designated as SOAP 1.2, and the specification is now broken into two parts. Part 1 describes the SOAP messaging framework and envelope specification. Part 2 describes the SOAP encoding rules, the SOAP-RPC convention, and HTTP binding details.

Send Soap Request Request with Credential using SoapClient

namespace test{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Addressing;
using Microsoft.Web.Services3.Messaging;
using System.Web.Services.Protocols;
using System.Net;
using System.Web;
using System.Configuration;

class OutgoingSoapClient : SoapClient {

public SoapEnvelope GetResponse()
{
try {
string username = "UserName";
string password = "Password"
distAdd="http://localhost/Service1.ashx"
System.Net.CredentialCache credCache = new System.Net.CredentialCache();
credCache.Add (new Uri(distAdd.ToString()), "Basic", new NetworkCredential(username, password));
SoapHttpOutputChannel httpchannel = (SoapHttpOutputChannel)
this.Channel;
httpchannel.Options.Credentials = credCache;
httpchannel.Options.Timeout = 30000;
SoapEnvelope response = this.SendRequestResponse(action, request);
return response;
}
}
}