locked
Still Having Zero Success Consuming 3rd Party Web Service RRS feed

  • Question

  • I've been fussing with this for the better part of two years. I've read through every single tutorial. I'm dying for someone to help me actually understand what piece I'm just missing in all of this.

    I subscribe to a web service for our drivers and their GPS location information. It has a methods GetAllDrivers and GetDriverByID.

    I need for this service to be called, and update all information for all my drivers to an entity I can use at my will in different screens. I do not want to call the web service for individual drivers each time I load a screen. I want to update all data once or twice a day.

    As I understand the answer to this is a RIA Service correct? If so I am just not having any luck getting a RIA service to work. I know I could just pay someone to do this, but I'm a little stubborn as I really want to learn how to do this.

    Would anybody be willing to have a back and forth with me without pointing me to some tutorial that eventually overlooks important pieces I need to understand?

    I think maybe I just need to understand the connection string in RIA class, how and when this relates to the wsdl part of my installed Web Service, and how the entity table is created with the columns defined by service. Does the service create all the different columns for the entity?

    Please help me find the light



    • Edited by MrGlimm Sunday, August 14, 2016 4:24 PM
    Sunday, August 14, 2016 4:23 PM

Answers

  • There are a number of ways to accomplish what you need but the most simplistic (IMO) is to develop a Console Application that you schedule to run X number of times a day.

    The steps I would follow would be:

    • Create a new Console application in Visual Studio.
    • Open your Lightswitch project in another instance of VS and run it.
    • in the Console app, click add Service Reference and use the Address http://localhost:XXXX/ApplicationData.svc/ (where XXXX is the port used to develop your LS app). Use the namespace ApplicationDataProxy. Press Ok and you will generate a WCF Data Services client proxy.
    • The WCF Data Services client is documented here.
    • To connect to LS, use logic like the following to create a context from the proxy. You will then be able to access all your LS data like you would on the LS server project. Note that this snippet is from a Windows Forms app with server, userName and password text boxes for my parameters. You can either hard code these values or pass them on the command line.

    private ApplicationData GetApplicationData() {

    var endPoint = $"http://{server.Text}/ApplicationData.svc"; var context = new ApplicationDataProxy.ApplicationData(new Uri(endPoint)); if (!string.IsNullOrEmpty(userName.Text)) { var credentials = new NetworkCredential(userName.Text, password.Text); context.Credentials = credentials; context.Timeout = 60 * 5; } return context; }

    • Once you are able to query, update and insert data in your LS app, you can add the Service Reference for your third party service and add the logic you want. There are any number of websites that demonstrate generating a proxy for WSDL and using the generated code.
    • You would now use the Windows Scheduler to schedule your batch operations once or twice a day. I use this all the time and it works great.

    Notes:

    • The Service generated from WSDL is different than the WCF Data Services.
    • The WCF Data Service client is not high performance.
    • To create a new entity, the Create method needs a 0 for the Id column and null for the rowversion column like:
    			var contact = Contact.CreateContact(0, firstName, lastName, salutation, null);
    

    The following is a snippet to add a driver in one of my LS systems using the data services client:

    			var contact = Contact.CreateContact(0, firstName, lastName, salutation, null);
    			service.AddToContacts(contact);
    			service.SetLink(newDriver, "Contact", contact);
    			service.AddLink(carrier, "Contacts", contact);
    
    			contact.Occupation = "Driver";
    

    I realize that my code snippets are a little out of context but they should give you some idea where to look in the documentation.

    Good luck!


    • Proposed as answer by Angie Xu Thursday, August 25, 2016 5:34 AM
    • Marked as answer by Angie Xu Thursday, August 25, 2016 5:34 AM
    Monday, August 15, 2016 6:48 PM

All replies

  • There are a number of ways to accomplish what you need but the most simplistic (IMO) is to develop a Console Application that you schedule to run X number of times a day.

    The steps I would follow would be:

    • Create a new Console application in Visual Studio.
    • Open your Lightswitch project in another instance of VS and run it.
    • in the Console app, click add Service Reference and use the Address http://localhost:XXXX/ApplicationData.svc/ (where XXXX is the port used to develop your LS app). Use the namespace ApplicationDataProxy. Press Ok and you will generate a WCF Data Services client proxy.
    • The WCF Data Services client is documented here.
    • To connect to LS, use logic like the following to create a context from the proxy. You will then be able to access all your LS data like you would on the LS server project. Note that this snippet is from a Windows Forms app with server, userName and password text boxes for my parameters. You can either hard code these values or pass them on the command line.

    private ApplicationData GetApplicationData() {

    var endPoint = $"http://{server.Text}/ApplicationData.svc"; var context = new ApplicationDataProxy.ApplicationData(new Uri(endPoint)); if (!string.IsNullOrEmpty(userName.Text)) { var credentials = new NetworkCredential(userName.Text, password.Text); context.Credentials = credentials; context.Timeout = 60 * 5; } return context; }

    • Once you are able to query, update and insert data in your LS app, you can add the Service Reference for your third party service and add the logic you want. There are any number of websites that demonstrate generating a proxy for WSDL and using the generated code.
    • You would now use the Windows Scheduler to schedule your batch operations once or twice a day. I use this all the time and it works great.

    Notes:

    • The Service generated from WSDL is different than the WCF Data Services.
    • The WCF Data Service client is not high performance.
    • To create a new entity, the Create method needs a 0 for the Id column and null for the rowversion column like:
    			var contact = Contact.CreateContact(0, firstName, lastName, salutation, null);
    

    The following is a snippet to add a driver in one of my LS systems using the data services client:

    			var contact = Contact.CreateContact(0, firstName, lastName, salutation, null);
    			service.AddToContacts(contact);
    			service.SetLink(newDriver, "Contact", contact);
    			service.AddLink(carrier, "Contacts", contact);
    
    			contact.Occupation = "Driver";
    

    I realize that my code snippets are a little out of context but they should give you some idea where to look in the documentation.

    Good luck!


    • Proposed as answer by Angie Xu Thursday, August 25, 2016 5:34 AM
    • Marked as answer by Angie Xu Thursday, August 25, 2016 5:34 AM
    Monday, August 15, 2016 6:48 PM
  • I was actually given a console test app by the vendor. This method makes a little more sense, and I've been trying to understand the generated code from the service. I really appreciate the input I will try to give this a go and let you know my results.

    Thanks!!

    Thursday, August 25, 2016 8:39 AM