NAV 2013 - Webservice call for Codeunit (without reference)

THUSTHUS Member Posts: 5
edited 2013-09-10 in NAV Three Tier
Hi Guys,

I like to try a simple codeunit call and get the hardcoded string back. And i like to do that without adding web reference.
I tried this sample but without succes: http://stackoverflow.com/questions/1712 ... eb-service

Are there anyone who can make a simple sample if i want to get a response from a codeunit function?

Sample:
A codeunit with one parameter function.
HellowWorld(string name) -> EXIT('Hello ' + name)

And i like to get Hello John in a string in c#..

The sample i have is like this:
string requestString = @"<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Test xmlns="urn:microsoft-dynamics-schemas/codeunit/test"></Test></soap:Body></soap:Envelope>";
System.Net.HttpWebRequest request;
System.Net.HttpWebResponse response = null;
string url = "http://dev.vava.dk:7047/DynamicsNAV70/WS/CRONUS%20Danmark%20A%2FS/Codeunit/test";

byte[] requestBuffer = null;
System.IO.Stream postStream = null;
System.IO.Stream responseStream = null;
System.IO.StreamReader responseReader = null;
request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.ProtocolVersion = new Version(1, 1);
request.Method = "POST";

request.Headers.Add("SOAPAction", @"urn:microsoft-dynamics-schemas/codeunit/test:HelloWorld");
request.ContentType = @"application/xml; charset=utf-8";
requestBuffer = System.Text.Encoding.ASCII.GetBytes(requestString);
request.ContentLength = requestBuffer.Length;
request.Credentials = new System.Net.NetworkCredential("thusan", "Cey_121212");
postStream = request.GetRequestStream();
postStream.Write(requestBuffer, 0, requestBuffer.Length);
postStream.Close();

response = (System.Net.HttpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();
string response_result = string.Empty;
if (responseStream != null)
{
responseReader = new System.IO.StreamReader(responseStream);
response_result = responseReader.ReadToEnd();
}
Label1.Text = response_result;


But i think it's wrong :) i hope there are someone who can help me :)

Have a nice day!

Comments

Sign In or Register to comment.