Access via SoapHttpClientProtocol ("Add Web Reference")

  • There is another way to access SOAP services using the SoapHttpClientProtocol class, generated by "Add Web Reference". This method can also be applied to xServer internet.

  • 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 the dialog for “Add Web Reference” add the url of the xServer with a “?WSDL” parameter. There is a bug in Visual Studio which triggers popups with warnings. You can close and ignore them.

    Learn how to add a Web Reference.

  • After the import, the "app.config" or "web.config" file should look like this:

<applicationSettings>
    <MyTestApplication.Properties.Settings>
        <setting name="MyTestApplication_XRoute_XRouteWSService" serializeAs="String">
            <value>https://xroute-eu-n-test.cloud.ptvgroup.com/xroute/ws/XRoute</value>
        </setting>
    </MyTestApplication.Properties.Settings>
</applicationSettings>
  • 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 : XRouteWSService
{
    public XRouteWSClientWithCredentials()
    {
        this.Credentials = new NetworkCredential("xtok", <your token>);
    }
}
  • You can use the inherited class the same way as the on-premise version now.

public static void Test()
{
    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 { wrappedProperties = new[] { new CallerContextProperty { key = "CoordFormat", value = "OG_GEODECIMAL" } }
     });
   
     System.Console.WriteLine("Distance: " + xRouteResult.info.distance);
}
  • The output should now look like this: