function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gregsgregs 

create custom SOAP message using .NET WebRequest class

Is it possible to for a client application using the WebRequest .NET class to create a custom SOAP request that can send an http request via the web services api and parse the response? I know i need to include the current session id and server url in the request, but how do i create the rest of the request content? What i want to do is call the merge fields servlet, /servlet/MergeFields.servlet (previously used by the connect for office toolkit and office toolkit 3.0) and retrieve the xml response it sends back. How can i do this? Can someone point me to some sample .net source code? Here is what i have so far:

//hardcode mergefield servlet url since there is no web services api method to get it
String url = host + "/servlet/servlet.MergeFields";
String postData = "?encoding=UTF-8";

//create request to get mergefields from salesforce mergefields servlet
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "text/xml";
request.ContentLength = postData.Length;

//how do i add the session and login credentials here?
//and is the url in the create call above the url i want to send, or is is the soap endpoint, something like
//https://na7.salesforce.com/services/Soap/u/17.0

//encode data
byte[] data = Encoding.ASCII.GetBytes(postData);
Stream input = request.GetRequestStream();
input.Write(data, 0, data.Length);
input.Close();

//get response
HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
Stream respStream = myResponse.GetResponseStream();

StreamReader streamRead = new StreamReader(respStream);
String respStr = streamRead.ReadToEnd();

XmlDocument doc = new XmlDocument();
doc.LoadXml(respStr);