Connection NAV 2017 Web Service (Codeunit) with Universal Windows App

Hi,
I hope someone can help me out. I'm just interested in trying out the new Windows Template Studio from VS2017. (btw. it's great)
I Created an app with Navigation Pane and MVVM Light + Grid. Nothing special so far.

In NAV I have a Codeunit Web Service with two parameters. (Request, Response) where Response is by Reference (VAR). I just write Response:= "Hello World" in the Function.

I'm strictly not able to get any result back with my app. I don't post any code here because my code is rubbish. I tried many ways.

In a simple Windows Forms application, I can connect through System.Web.Service

Like this ... Where ProcessRequest is my Function in the Codeunit and Webserv is the Published Service name
using System;
using System.Net;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Windows.Forms;

namespace WebserviceTest
{
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [WebServiceBinding(Name = "Webserv_Binding", Namespace = "urn:microsoft-dynamics-schemas/codeunit/Webserv")]
    public class NAV2017ServiceClient : SoapHttpClientProtocol
    {
        public NAV2017ServiceClient(string url, string userName, string password, string domain, int timeout)
        {
            this.Url = url;
            this.Timeout = timeout * 1000;
            if (string.IsNullOrEmpty(userName))
                this.UseDefaultCredentials = true;
            else
                this.Credentials = (ICredentials)new NetworkCredential(userName, password, domain);
        }


        [SoapDocumentMethod("urn:microsoft-dynamics-schemas/codeunit/Webserv:ProcessRequest", ParameterStyle = SoapParameterStyle.Wrapped, RequestNamespace = "urn:microsoft-dynamics-schemas/codeunit/Webserv", ResponseElementName = "ProcessRequest_Result", ResponseNamespace = "urn:microsoft-dynamics-schemas/codeunit/Webserv", Use = SoapBindingUse.Literal)]
        public void ProcessRequest(string request, ref string response)
        {
      
            //MessageBox.Show(this.Url.ToString());            
            object[] objArray = this.Invoke("ProcessRequest", new object[2]
            {
                (object) request,
                (object) response
            });
            
            response = (string)objArray[0];


        }

        protected override WebRequest GetWebRequest(Uri uri)
        {
            WebRequest rq = base.GetWebRequest(uri);            
            return rq;
        }

    }
}

worked like charm :). But now I do not have a clue how I could connect to NAV and get my simple response back.

If anyone has some time left and knowledge in this I would love to get an answer how I can achieve this.

It's nothing I'm working on for a customer so there is no need to hurry for me. It's just a "would love to know" thing.

greetings

Answers

  • devdronedevdrone Member Posts: 14
    I would suggest you to add the web service in visual studio through the Add reference. If you add web service in visual studio like this, then you will be able to get your function directly in VS.
Sign In or Register to comment.