Receiving SOAP Messages in NAV2009

iansilversiansilvers Member Posts: 38
edited 2014-06-11 in NAV Three Tier
I hope someone can give me a bit of a help here. I have a customer who is looking to interface their NAV2009 SP1 system with an external warehousing application. We are dealing with SOAP documents, and I have to send messages about items, and orders to the warehouse, and receive back order despatch messages, stock balances etc from the warehouse. I am able to send the outbound documents to external web service without any problems, however, I am struggling to get the return messages back into NAV.

A sample inbound XML message that I am trying to bring into NAV looks like
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:ref1="http://localhost/navision.wsdl">
    <SOAP-ENV:Body>
        <ref1:StockAdjustmentMessage>
            <stockAdjustment>
                <itemCode>ITEM3</itemCode>
                <quantityAdjusted>-330</quantityAdjusted>
                <reasonCode>QA</reasonCode>
            </stockAdjustment>
        </ref1:StockAdjustmentMessage>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I have one codeunit in NAV which is exposed as a web service to handle the receipt of messages. Within the codeunit I have a function for each message - in this case a function called StockAdjustmentMessage, with an XMLPort as the only parameter to receive the stockAdjustment content of the XML message.
    PROCEDURE StockAdjustmentMessage@1000000008(stockAdjustment@1000000000 : XMLport 50001) OK : Boolean;
    BEGIN
      OK := stockAdjustment.IMPORT;
    END;

When I try to access this using a simple .NET program doing a POST of the SOAP message, I am getting a 500 message, and the application event log on the server reports "Parameter stockAdjustment in method StockAdjustmentMessage in service ReflexInbound is null!"

Here is the code for my test program
       static void Main(string[] args)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(@"c:\StockAdjustment.xml");

            HttpWebRequest request;
            HttpWebResponse response;
            Stream responseStream;
            StreamWriter writer;
            StreamReader reader;

            string url = @"http://iis:7047/DynamicsNAV/WS/TestCompany/Codeunit/ReflexInbound";

            request = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
            request.ProtocolVersion = new Version(1, 1);
            request.Method = "POST";
            request.ContentType = @"application/xml; charset=utf-8";
            request.Accept = "text/xml";
            request.UseDefaultCredentials = true;
            request.Headers.Add("SOAPAction", @"StockAdjustmentMessage");
            
            writer = new StreamWriter(request.GetRequestStream(), Encoding.UTF8);
            writer.Write(xmlDoc.OuterXml);
            writer.Flush();
            writer.Close();

            response = (HttpWebResponse)request.GetResponse();
            responseStream = response.GetResponseStream();
            string response_result = string.Empty;
            if (responseStream != null)
            {
                reader = new StreamReader(responseStream);
                response_result = reader.ReadToEnd();
            }

The question is how do I get the actual message body into NAV? I have been working on this for a few days, and do not seem to be making any headway. Any help is greatly appreciated.

Best Answer

  • iansilversiansilvers Member Posts: 38
    Answer ✓
    Problem resolved. Turns out to be with the Namespaces on the XML document.

Answers

  • iansilversiansilvers Member Posts: 38
    Answer ✓
    Problem resolved. Turns out to be with the Namespaces on the XML document.
Sign In or Register to comment.