How to POST SOAP Envelope as Request/ Response in Microsoft Dynamics NAV Web Service

Hi,

I am trying to post SOAP Envelope directly to Dynamics NAV Webservices using HttpWebRequest, HttpWebResponse.

i.e.

private void button1_Click(object sender, EventArgs e)

{

string requestString = LoadData();

HttpWebRequest request;

HttpWebResponse response = null;

string url = “”>localhost:7047/…/Insync_Item";

byte[] requestBuffer = null;

Stream postStream = null;

Stream responseStream = null;

StreamReader responseReader = null;

request = (HttpWebRequest)WebRequest.Create(url);

request.ProtocolVersion = new Version(1,1);

request.Method = “POST”;

request.Headers.Add(“SOAPAction”, @“urn:microsoft-dynamics-schemas/page/insync_item:create”);

//request.Headers.Add(“Content-Type”, @“text/xml; charset=utf-8”);

request.ContentType = @“application/xml; charset=utf-8”;

requestBuffer = Encoding.ASCII.GetBytes(requestString);

request.ContentLength = requestBuffer.Length;

request.UseDefaultCredentials = true;

postStream = request.GetRequestStream();

postStream.Write(requestBuffer, 0, requestBuffer.Length);

postStream.Close();

response = (HttpWebResponse)request.GetResponse();

responseStream = response.GetResponseStream();

string response_result=string.Empty;

if (responseStream != null)

{

responseReader = new StreamReader(responseStream);

response_result = responseReader.ReadToEnd();

}

MessageBox.Show(response_result);

}

private string LoadData()

{

// throw new NotImplementedException();

XmlDocument oCustomer = new XmlDocument();

oCustomer.Load(@“C:\Users\kishore.LOCAL.000\Desktop\NAV_DEMO\NAV_DEMO\bin\Debug\input\item.xml”);

return oCustomer.InnerXml;

}

<soapenv:Envelope xmlns:soapenv="">schemas.xmlsoap.org/…/" xmlns:ins=“urn:microsoft-dynamics-schemas/page/insync_item”>

[

soapenv:Header/

soapenv:Body

ins:Create

ins:Insync_Item

ins:Key?</ins:Key>

ins:No1234</ins:No>

ins:DescriptionTest Item</ins:Description>

</ins:Insync_Item>

</ins:Create>

</soapenv:Body>

</soapenv:Envelope>

This envelope is Create action of webservice. But following line

response = (HttpWebResponse)request.GetResponse();

returning error The remote server returned an error: (500) Internal Server Error.

Please help me where I am doing wrong. I need to insert data using soap envelope only.

Thanks

Surajit

](http://schemas.xmlsoap.org/soap/envelope/)

Hi all,

i have done…

Can you tell what was the problem?