Accessing the methods of xLocate service via WebClient in C#

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
Post Reply
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

Accessing the methods of xLocate service via WebClient in C#

Post by webdirekt »

We want to create the dll which calls the methods of xLocate that is findAddress to get the geo-coordinates of given address.

So how can we call the method findAddress of xLocate, pass the Address object to that method and at last get the result without using the web service reference.

Is there any way to call the methods of xLocate service via WebClient.
LNM_PTV
Posts: 14
Joined: Mon Apr 18, 2016 12:25 pm

Re: Accessing the methods of xLocate service via WebClient i

Post by LNM_PTV »

Hello,

here are two links to our Website where you can find Information about how to acces the xlocate Service in C#.

http://xserver.ptvgroup.com/en-uk/cookb ... lications/

http://xserver.ptvgroup.com/en-uk/cookb ... s-classes/

Does that help you?

Best regards,
Lars
Lars Moritz
Technical Consultant
PTV GROUP, Germany
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

Re: Accessing the methods of xLocate service via WebClient i

Post by webdirekt »

Dear Dr. Moritz,
Thanks for your help, we are moving ahead and will contact you in case we need any help.

Kind Regards
Ramanan
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

Re: Accessing the methods of xLocate service via WebClient i

Post by webdirekt »

Hello,

we have checked the client dlls which you have given to us, but in those dlls, we found only xroute client base available. Do we have to reference any thing else?
also in that dll, we need user id and password to initialize xroute client base. How can we get user id and password or xtoken to use xroute client base.

We have used HttpWebRequest to request xLocate using JSON object to get JSON result.
Sample code,

Code: Select all

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(domain + "/xlocate/rs/XLocate/findAddress");
            webRequest.ContentType = "application/json;charset=\"utf-8\"";
            webRequest.Accept = "application/json";
            webRequest.Method = "POST";

            // get content bytes
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            Byte[] byteArray = encoding.GetBytes(jsonAddress);

            webRequest.ContentLength = byteArray.Length;

            // add content into request steam
            using (Stream dataStream = webRequest.GetRequestStream())
            {
                 dataStream.Write(byteArray, 0, byteArray.Length);
            }

            // get response
            using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse())
            {
                 // read response into StreamReader
                 using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                 {
                      // get response into a string variable
                      string jsonResponse = rd.ReadToEnd();
                      console.write(jsonResponse);
                 }
             }
Is there any other way, we can achieve same result as above?

Kind regards,
Webdirekt Team
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Accessing the methods of xLocate service via WebClient i

Post by Bernd Welter »

Hi there,

ON PREMISE: For access to a local xServer you don't have to specify credentials (as long as you use a standard configuration where authentification is disabled by default).
ON CLOUD: For access to xServer INTERNET you need to set Username="xtok" and Password=yourtoken.

The DLLs: you should find the required x...dll's within the /clients folder of each server.
Worst case is to collect the different dll's manually.

Does this answer the question?

Best regards,
Bernd

PS: I usually create my connection classes via WSDL.exe.
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

Re: Accessing the methods of xLocate service via WebClient i

Post by webdirekt »

Hi Bernd,
Thanks for the details.
We have now used the xlocate-dotnetclient.dll and xserverbase-dotnet-client.dll in our program and it works fine.

Regards
Ramanan
Post Reply