Access via WCF ("Add Service Reference")

  • This guideline shows how to access xServer internet in .NET client applications by importing the WSDL in Visual Studio. For the current Visual Studio versions the standard way of using SOAP services is WCF.

  • While xServer internet uses HTTP basic authentication with <user>/<password>, it is highly recommended to work with the token assigned to your subscription using the combination “xtok”/<token>. Using the token is a safer way than using your far more sensible account data.

  • In your Visual Studio project select “Add Service Reference” and add the url of the xServer with a “?WSDL” parameter.

     

  • After having imported the WSDL, you have to adapt the configuration. Change the "app.config" file for windows client applications or the "web.config" file for ASP.NET projects.

    • Add the element <transport clientCredentialType="Basic" /> to the "security" element as shown below.
    • For xRoute and xTour, you should set "maxReceivedMessageSize" to the maximum (2147483647).

    After having changed the configuration, it should look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
              <binding name="XRouteWSBinding" maxReceivedMessageSize="2147483647">
                <security mode="Transport">
                  <transport clientCredentialType="Basic" />
                </security>
              </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://xroute-eu-n-test.cloud.ptvgroup.com/xroute/ws/XRoute" binding="basicHttpBinding"
                bindingConfiguration="XRouteWSBinding" contract="XRouteServiceReference.XRouteWS"
                name="XRouteWSPort" />
        </client>
    </system.serviceModel>
</configuration>
  • To access the service, you have to set the credentials for your client class. The easiest way to do this is to inherit from the generated class and set the credentials in the constructor.

public class XRouteWSClientWithCredentials : XRouteWSClient
{
    public XRouteWSClientWithCredentials()
    {
        ClientCredentials.UserName.UserName = "xtok";
        ClientCredentials.UserName.Password = <insert your token here>;
    }
}
  • You can use the inherited class the same way as the on-premise version now.

public static void Run()
{
    var xRouteClient = new XRouteWSClientWithCredentials();
   
    var xRouteResult = xRouteClient.calculateRoute(new[]{
            new WaypointDesc{wrappedCoords = new []{new Point{point = new PlainPoint{x = 7.10, y = 50.73}}}},
            new WaypointDesc{wrappedCoords = new []{new Point{point = new PlainPoint{x = 10.00, y = 53.55}}}}
         },
         null, null, new ResultListOptions(), // just need the distance
         new CallerContext { rappedProperties = new[] { new CallerContextProperty { key = "CoordFormat", value = "OG_GEODECIMAL" } }
     });
   
    System.Console.WriteLine("Distance: " + xRouteResult.info.distance);
}
  • The output should now look like this: