I'm trying to call a web service from a D365 CRM Online plugin and I always get "The remote server returned an error: (500) Internal Server Error."
When I don't use SOAPAction as a header, it seems I am getting a kind of response from the server (I think it's the wsdl). But I know I should use the soapaction header.
Below is my code:
string rawXml = "" "" "" $"{serviceReceiptNo}" $"{serialNoName}" $"{itemNoName}" $"${caseNo}" "" "" ""; byte[] requestInFormOfBytes = System.Text.UTF8Encoding.UTF8.GetBytes(rawXml); string url = "http://***/Codeunit/ServiceMgt"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Headers.Add("SOAPAction", "urn:microsoft-dynamics-schemas/codeunit/ServiceMgt:UpdateTicketNumber"); request.Method = "POST"; NetworkCredential myNetworkCredential = new NetworkCredential("***@***", "***"); request.Credentials = myNetworkCredential; request.ContentType = "text/xml;charset=utf-8"; request.ContentLength = requestInFormOfBytes.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(requestInFormOfBytes, 0, requestInFormOfBytes.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream responseStream = response.GetResponseStream(); string responseStr = new StreamReader(responseStream).ReadToEnd(); tracingService.Trace("RESPONSE" responseStr); }
Any help would be greatly appreciated.