banner



How To Use Service Reference In C#

Access via WCF ("Add together Service Reference")

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

  • While xServer internet uses HTTP basic authentication with <user>/<countersign>, 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.

  • Subsequently having imported the WSDL, y'all have to adapt the configuration. Change the "app.config" file for windows client applications or the "web.config" file for ASP.Cyberspace projects.

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

    After having inverse the configuration, information technology should look similar this:

            <?xml version="1.0" encoding="utf-eight" ?> <configuration>     <system.serviceModel>         <bindings>             <basicHttpBinding>               <bounden name="XRouteWSBinding" maxReceivedMessageSize="2147483647">                 <security mode="Send">                   <transport clientCredentialType="Basic" />                 </security>               </binding>             </basicHttpBinding>         </bindings>         <customer>             <endpoint address="https://xroute-eu-northward-examination.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 grade. The easiest way to do this is to inherit from the generated class and set the credentials in the constructor.

            public grade XRouteWSClientWithCredentials : XRouteWSClient {     public XRouteWSClientWithCredentials()     {         ClientCredentials.UserName.UserName = "xtok";         ClientCredentials.UserName.Password = <insert your token here>;     } }                      
  • Y'all tin can use the inherited class the same way as the on-premise version at present.

            public static void Run() {     var xRouteClient = new XRouteWSClientWithCredentials();      var xRouteResult = xRouteClient.calculateRoute(new[]{             new WaypointDesc{wrappedCoords = new []{new Point{point = new PlainPoint{x = vii.x, y = fifty.73}}}},             new WaypointDesc{wrappedCoords = new []{new Point{signal = new PlainPoint{x = 10.00, y = 53.55}}}}          },          null, null, new ResultListOptions(), // simply need the altitude          new CallerContext { rappedProperties = new[] { new CallerContextProperty { primal = "CoordFormat", value = "OG_GEODECIMAL" } }      });      System.Panel.WriteLine("Distance: " + xRouteResult.info.altitude); }                      
  • The output should now look like this:

How To Use Service Reference In C#,

Source: https://www.ptvgroup.com/en/solutions/products/ptv-xserver/developer-guide/programming-examples/c-sharp/accessing-ptv-xserver-internet-in-net-applications/access-via-wcf-add-service-reference/

Posted by: heathhichit.blogspot.com

0 Response to "How To Use Service Reference In C#"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel