System.Net.XmlHttpRequest.SetRequestHeader C# (CSharp) Method

SetRequestHeader() public method

public SetRequestHeader ( string header, string value ) : void
header string
value string
return void
        public void SetRequestHeader(string header, string value)
        {
        }

Usage Example

        private static XmlDocument GetResponse(string soapXmlPacket, string action, Action<object> asyncCallback)
        {
            bool isAsync = (asyncCallback != null);

            string xml = getSoapEnvelope(soapXmlPacket);
            string msg = null;
            XmlHttpRequest xmlHttpRequest = new XmlHttpRequest();

            xmlHttpRequest.Open("POST", GetServerUrl() + "/XRMServices/2011/Organization.svc/web", isAsync);
            xmlHttpRequest.SetRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/" + action);
            xmlHttpRequest.SetRequestHeader("Content-Type", "text/xml; charset=utf-8");

            // This is only needed when debugging via localhost - and accessing the CRM webservices cross domain in chrome
            if (WithCredentials)
            {
                Script.Literal("{0}.withCredentials = true;", xmlHttpRequest);
            }

            if (isAsync)
            {
                xmlHttpRequest.OnReadyStateChange = delegate()
                {
                    if (xmlHttpRequest == null)
                        return;
                    if (xmlHttpRequest.ReadyState == ReadyState.Loaded)
                    {
                        // Capture the result
                        XmlDocument resultXml = xmlHttpRequest.ResponseXml;
                        string errorMsg = null;
                        if (xmlHttpRequest.Status != 200)
                        {
                            errorMsg = GetSoapFault(resultXml);
                        }
                        // Tidy Up
                        Script.Literal("delete {0}", xmlHttpRequest);

                        xmlHttpRequest = null;

                        if (errorMsg != null)
                        {
                            asyncCallback(errorMsg);
                        }
                        else
                        {
                            // Callback
                            asyncCallback(resultXml);
                        }
                    }
                };

                xmlHttpRequest.Send(xml);

                return null;
            }
            else
            {
                xmlHttpRequest.Send(xml);

                // Capture the result
                XmlDocument resultXml = xmlHttpRequest.ResponseXml;

                // Check for errors.
                if (xmlHttpRequest.Status != 200)
                {
                    msg = GetSoapFault(resultXml);
                }
                // Tidy Up
                Script.Literal("delete {0};", xmlHttpRequest);
                xmlHttpRequest = null;

                if (msg != null)
                {
                    throw new Exception("CRM SDK Call returned error: '" + msg + "'");
                }
                else
                {

                    // Return
                    return resultXml;
                }
            }
        }