0

I try to access the Navision 2009 R2 web service by generating a SOAP message from C#. I get the response only if the codeunit's function I call has no parameters.

Example for codeunit RunJob function Test (no parameters, returns a hardcoded string):

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
</Test>
</soap:Body>
</soap:Envelope>

As result I get that string...

Example for same codeunit RunJob function RunJob (takes 1 string parameter named parameter, returns an internal server error):

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">
<parameter>aaaa</parameter>
</RunJob>
</soap:Body>
</soap:Envelope>

As result I get the error (WebResponse wr = request.GetResponse();) instead of the needed info.

The most interesting thing is that it worked before. The only changes (as for me) - NAV 2013 was installed.

Has anyone experienced the same issue or knows the solution?

P.S. Here is a part of the web service definition for the RunJob function:

<element name="Runjob">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="parameter" type="string"/>
</sequence>
</complexType>
</element>
<element name="Runjob_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
</sequence>
</complexType>
</element>
Alex Peck
  • 4,603
  • 1
  • 33
  • 37
user1390456
  • 96
  • 1
  • 8

2 Answers2

1

It was all about the function/variables naming. The first letter of the each parameter of the function should be small one. The SOAP body should be like this ("codeunit" is in lowercase, but it's name is as exposed in NAV)

<RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/RunJob">
...params...
</RunJob>

the Request header (codeunit name in lower case, function name as it is)

"urn:microsoft-dynamics-schemas/codeunit/runjob:RunJob"
user1390456
  • 96
  • 1
  • 8
0

It sound awkward but try to put

<soap:Body><RunJob xmlns="urn:microsoft-dynamics-schemas/codeunit/runjob">

in single line, i.e. no carriage return between Body and RunJob.

Mak Sim
  • 2,148
  • 19
  • 30
  • I write the whole request in a single line. The carriages in the example above are only for the easiness of reading. – user1390456 Jun 21 '13 at 11:56
  • Http 500 in most cases means problems with request. Try to generate sample request with any ws-consuming tool like SOAPui. Nightly builds of soapui can work with Nav ws an NTLM auth. – Mak Sim Jun 24 '13 at 05:43
  • Yes, I do use SOAPui, the pieces of XML in my question are taken from there (both requests/answers which i do/get with SOAPui are equal to requests/answers made from C#). And earlier (~2 months ago) SOAPui could successfully deal with transferring of the function's parameters and get the correct answer from WS. I cannot imagine what went wrong: neither C# code nor anything else was changed, I just put that project aside, and when I came back to it the functions with parameters stopped working. The only thing happened - installation of NAV 2013 in parallel to NAV 2009 R2 during that "pause" – user1390456 Jun 24 '13 at 10:04
  • Maybe service installed by Nav7 just overwrited your service with the same name and now you using wrong web service? Or they share same port and that what is causing errors. Try re-consume wsdl with soapui. Also try recompile Nav codeunit. If you used some automation variables an then uninstalled required libraries it may not work well. – Mak Sim Jun 25 '13 at 23:34
  • And if nothing works you can use debug mode to generate c# code and debug your particular request to see where it crashes. – Mak Sim Jun 25 '13 at 23:39