Web Connection
No interface, just data in Web Connection?
Gravatar is a globally recognized avatar based on your email address. No interface, just data in Web Connection?
  Simon
  All
  Sep 10, 2018 @ 08:32am

Hi Rick

Having watched and read just about everything we can find regarding Web Connection - it looks like another great product from West Wind.

However, we need to build a web service which accepts XML data inputs in the form of SOAP requests to then append to VFP tables as normal. There will be no browser interface.

We cannot find any references to XML data input. Is this easy to do in Web Connection?

Thanks in advance

Regards

Simon

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Rick Strahl
  Simon
  Sep 10, 2018 @ 11:10am

Web Connection has support for creating services, but there's no explicit interface for building SOAP based services any longer. You can easily create JSON or XML services however using the wwRestService class.

At this time we recommend using REST services using JSON as that is what is most common for Web based service interfaces these days. You can look at a walk through here:

As to creating SOAP services, I have a few White Papers that talk about this topic using .NET to create the front end and calling into FoxPro code or using OleDb data access from the .NET code.

We've discontinued built-in SOAP support in Web Connection years ago because FoxPro internally just doesn't have the tools to generate the appropriate strongly typed interfaces required for SOAP - there's no proper type reflection API in FoxPro that makes this not possible to walk a code hierarchy. Using .NET provides the ability to create classes that represent your model and have that automatically reflected in the tooling and you get the strong typing and you can pass the logic into FoxPro code.

One reason REST services are more popular these days is because they offer the ability to bypass the strong type checking and don't require complex support code to call the service. With REST services you can just return FoxPro values and you're done. Unless there's an explicit requirement for SOAP, it's a good idea to explore JSON services.

Hope this helps,

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Simon
  Rick Strahl
  Sep 10, 2018 @ 02:43pm

Hi Rick

Thanks for the response. If we had the chance, JSON looks much better.

Unfortunately, we have to write an integration to an existing fixed data model whereby our service is listening for them posting data to us and the data is a SOAP XML package.

If traditional SOAP is no longer really supported, as long as we can receive the data stream from them and then parse it to exract the relevant data, do we really need a real SOAP solution? Couldnt they just POST() the file as a stream to us?

Thanks

Simon

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Rick Strahl
  Simon
  Sep 10, 2018 @ 07:32pm

Yes you can most definitely capture the raw XML data, but you'd have to manually parse it and then generate the result XML on your own. Ugly, but doable and you have to be really careful to generate properly typed XML results that match the existing service interface - it'll expect certain namespaces and types for the results so this can get take some time to get right.

The other option is to create an ASP.NET Web Service or WCF Web Service to match the existing service interface (which also can be tricky if it has to match exactly). With this you basically create the data model (structure) for the parameters and result values, and then either call a FoxPro COM object that fills the appropriate message objects to return. The advantage with this is that you will end up with a bone fide SOAP Web Service with proper WSDL and you can be sure that the data typing and SOAP formatting is all correct.

Either way - matching an existing service exactly is always tricky regardless which route you take.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Simon
  Rick Strahl
  Sep 11, 2018 @ 12:19pm

Thanks Rick

We have installed Web Connection, got it running and worked through all the samples - looks great.

We have read through all the documentation that came with it but have not yet been able to find out how to build a service to receive a stream / file of known name, when sent to us as an HTTPS POST(). We will re-read the docs.

Upon receipt of the data, we do not have to return anything other than an a "Success" acknowledgement on successful file processing.

What you suggest seems massively overcomplicated which probably means we have missed something fundamental. Why would we have to rebuild the XML? If we assume the received stream / file (which is in a fixed format) is a valid XML, can't we just process it as we would any other XML file & simply pull out the data & then put in a table?

We are sure this will be straight forward when we get the hang of it.

Cheers

Simon

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Rick Strahl
  Simon
  Sep 11, 2018 @ 04:12pm

If all you need to return is a simple 'success' result, then this is probably simple enough. But anything more complex you can easily run into encoding issues. You still need to return a SOAP envelope that wraps the data.

In short - yes you can do this 'manually' but just be aware of the caveats, especially if you need to parse nad return complex data.

Getting the POST buffer is easy:

lcXml = Request.Form()

Just for the record: Parsing and processing SOAP XML that is specific to a WSDL definition is not trivial. If you have to follow an exact format you have to send data in a very specific format. Getting the XML just right - especially the namespaces - can be difficult in the data you return. It's possible to do, but any change you make you end up having to fix the interface. Also you have to make sure you generate your XML through an XML parser to ensure the XML is properly encoded both for reading and writing.

I've seen this too many times where everything is fine during testing because the XML is exactly what you know it should be with simple values, but when live data comes in with special characters or specific namespace directives that affect the output, things can go wrong quickly.

There's a bit more to SOAP than just raw XML and while you can simulate this without using a proper SOAP server/client, for anything more than trivial data, it's often easier to use a proper SOAP processor (ie. .NET most likely) to handle that aspect reliably especially when you have all sorts of clients sending all sorts of data in funky variations 😃

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Simon
  Rick Strahl
  Sep 19, 2018 @ 10:37am

Hi Rick

Installed the shareware version of Web Connection and the demos work fine using localhost.

However, when we try to create a project, there is no response from the project.

We have followed the steps to the letter. The project is correctly generated.

Are there any obvious things that we might be doing wrong?

We create the project and then in VFP9, set the directory to the created project and then run the [ProjctName]Main.prg

Any thoughts?

Thanks

Simon

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Rick Strahl
  Simon
  Sep 19, 2018 @ 12:51pm

Did you run the server (ie. your application? DO myAppMain.prg)? I know obvious, but that's what it sounds like. Can you reach the default page (the static HTML page)? If not you're probably not navigting to the right place in the browser (ie. https://localhost/myApp/)

When the project is created there are instructions in the FoxPro desktop that tell you what you need to do to start up the server.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Simon
  Rick Strahl
  Sep 20, 2018 @ 04:23am

Hi Rick

Ok, got server running (don't know what issue was other than reinstall & reboot) and can now get a web page response from our funtion GetLeads() - great.

But we are not building a browser based solution - so next step is just data.

However we cannot seem to send it any any data. We have re-read all the help files and spent ages trawling the internet trying to find an example of sending & receiving an xml data stream (or any data other than file uploads or form data) but are stuck.

Fistly, we can't seem to send any data :

lMessage = 'Hello World'
oHTTP.AddPostKey()          
oHTTP.AddPostKey(lMessage)  
lcResult = oHTTP.HttpGet("http://localhost/AppName/GetLeads.wc") 

Can we not send data to localhost in this way? We have tried http and https and just localhost - no communication.

In our method it seems we only need your suggestion of lcXml = Request.Form() / Request.GetRawFormData() to capture the post buffer & we are all sorted from there.

This all looks really straight forward to use but we are obviously missing something fundamental.

Any thoughts as we need to get this sorted?

Thanks in advance

Simon

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Rick Strahl
  Simon
  Sep 20, 2018 @ 05:44pm

I'm not sure what you are asking. If you created a REST service application you should automatically have gotten a service based interface that can take simple parameters as input and return values for output that are automatically serialized into JSON.

For example:

FUNCTION CustomerQuery(loQueryParms)

select * from customers ;
    where lastname = loQUeryParms.Name AND
          entered > loQueryParms.MinEnteredDate
INTO CURSOR TQuery ;
ORDER By Entered DESC

loResult = CREATEOBJECT("EMPTY")
ADDPROPERTY(loResult,"count", _Tally)
ADDPROPERTY(loResult,"data","cursor:TQuery")

RETURN loResult

In this case the input expects a raw JSON object as input:

{
   Name: "Strahl",
   MinEnteredDate: ""2018-01-01T00:00Z"
}

JSON can be generated using wwJsonSerializer() from any FoxPro value, object or collection.

Now - you don't have to use a JSON Service and you can certainly use a standard HTML process class but you will have to format to return yourself in that case: Serialize it, set the proper content type, and stream it out.

Can we not send data to localhost in this way? We have tried http and https and just localhost - no communication.

Sure you can.

But you better make sure the server is running. To do this you need two instances of FoxPro running - one that's you 'client' running the HTTPGet request, one that's running the Web Connection server.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: No interface, just data in Web Connection?
  Simon
  Rick Strahl
  Sep 20, 2018 @ 06:59pm

REST service seems to sort it.

Thanks

© 1996-2024