web services webmethod consume in an extension?

web services webmethod consume in an extension?

  
Hello all,

I have a .net library I need to create a windows service to run on my Outsystems server then have an extension in C# use webmethods (or have heard them called endpoints) to send/receive data to/from the extension and the web service running on the server.  Any ideas/examples of how to do that?
Hi Jason,

Why do you need to use a separate service to use your library?
Can't you just import it directly in the extension? Or does it have some limitation that it needs to run as a service?

Regards,
João Rosado
This library is for making a (I believe) socket based connection between the Outsystems server and a device over ethernet.  I want to keep this connection open all the time.  I tried putting the connection in via extension to the Outsystems platform and it worked but the connection is being terminated after 30 seconds of being open either by Outsystems or by IIS.  The recommendation from Outsystems was to create a windows service to keep the connection open all the time with endpoints which the extension in Outsystems would be able to read/write data.  However, not something I have done before so wanted to see if anyone else had tried this.
Ok, looks like a good reason :)

For the consumption part on the OutSystems part is very easy, you don't even need an extension.
In your espace you can right click the Web Services folder and import a Web Reference directly from there.
It will only ask for the url of your service that will depend on how you create your service.

Do you also need help on creating the service?
There should be a good WCF Service template with everything you need in Visual Studio if you have the Web or a non-Express version of Visual Studio.


Regards,
João Rosado
Ok, have gotten to the point where I can make the web service running on my computer.  However, if I go to the consume web service and type in http://localhost/<service name> it says not found.  Suggestions?
Hi,

I'm assuming that it will not be running on port 80 (since IIS will already be using that), so it your url is missing at least the port number.
The rest will depend on how you implemented it, but I guess (if you used wcf) it should be something like this:
http://localhost:<port number>/<service name>.svc?wsdl
If you right click the svc file in visual studio it should have a debug option, that will open your browser on the correct url.

Regards,
João Rosado
Ok, update to this.

1) I am getting a major error as described above where if I set up the program and then run it as a windows service, apparently the windows service has to be run through iis for it to be accessable to the web or even to Outsystems running on the same box.  If you can get this working on your own box, please post instructions on how you did it without going through iis as I HOPE this will fix the closing after 30 seconds issue.

2) So second idea was to get the wcf service running just on the wcf test client running inside visual studio 2013 on the same box as the Outsystems platform.  Again - I get it running on the client, I can invoke the test method on the wcf test client but can't seem to get the Outsystems client to connect to that server, again even though its on the same box.

So unless someone else can show a procedure for one of the 2 above to connect to outsystems, I have pretty much given up on getting that to work.  My only path I can see now is to see if I can get a library for a packet based communications so that I don't have to have a permanent connection.  The PLC card itself supports CIP so I am looking into that.  If anyone has experience doing custom CIP and any pointers, let me know.
João Rosado wrote:
Hi,

I'm assuming that it will not be running on port 80 (since IIS will already be using that), so it your url is missing at least the port number.
The rest will depend on how you implemented it, but I guess (if you used wcf) it should be something like this:
http://localhost:<port number>/<service name>.svc?wsdl
If you right click the svc file in visual studio it should have a debug option, that will open your browser on the correct url.

Regards,
João Rosado
 So looking at this, I think this will only work if the windows service is published through iis which brings back my existing 30 second problem.
 
Hi Jason,

Don't give up! There is hope!
:)

Lets see I rushed this in ..so lets hope I don't skip a step.

1- Download the zip I attached. It's a Visual Studio project with a sample web service of a calculator based on this explanation:
http://msdn.microsoft.com/en-us/library/ms733069%28v=vs.110%29.aspx
Btw, to find it I just googled for "wcf in windows service" and followed the steps (well, didn't follow all the steps since I used a Windows Service wizard to skip a bit ahead).

2 - Open it in Visual Studio
3 - Built it
4 - Following the instructions on the microsoft link we need to use the "installutil" tool to install it
In a command line run:

%WinDir%\Microsoft.NET\Framework\v4.0.30319\installutil "<Path to where you unzipped it>\CalculatorWindowsService\CalculatorWindowsService\bin\Debug\CalculatorWindows.exe"

5 - I named the service on my sample by "CalculatorWindowsService", so open windows services and start it



6 - In the App.config I used this url as sample "http://localhost:9000/CalculatorServiceSample/servicename"
You can change it to any port and names that you wish.

7 - In Service Studio import the web reference





Hope this helps.


Regards,
João Rosado





Joao,

Thank you for the example!  Its good to know that this worked on yours.  I followed all the steps however a few items:

- I am using the version 9 so don't know if that is keeping me from accessing the web service.
- I added inbound and outbound firewall exceptions for port 9000 hoping that might fix it - no luck

The error I am getting back is "Couldn't access resource at http://localhost:9000/CalculatorServiceSample/servicename?wsdl  Unable to connect to the remote server  No connection could be made because the target machine actively refused it 127.0.0.1:9000.

Any ideas on what is causing that error?  (its one I have seen quite a bit of)
Can you access it in your browser?
Yes (firefox) and on the page it has this:
CalculatorService Service

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe http://localhost:9000/CalculatorServiceSample/servicename?wsdl

You can also access the service description as a single file:

http://localhost:9000/CalculatorServiceSample/servicename?singleWsdl

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:

C#

class Test
{
    static void Main()
    {
        CalculatorClient client = new CalculatorClient();

        // Use the 'client' variable to call operations on the service.

        // Always close the client.
        client.Close();
    }
}


Visual Basic

Class Test
    Shared Sub Main()
        Dim client As CalculatorClient = New CalculatorClient()
        ' Use the 'client' variable to call operations on the service.

        ' Always close the client.
        client.Close()
    End Sub
End Class
the address in the url bar of the firefox browser is http://localhost:9000/CalculatorServiceSample/servicename and this browser is open on the Outsystems server pc which is running windows server 2008 r2
So ..if it opens correctly in firefox it must also work inside Service Studio (on the same machine).

Is your service studio on another machine? If so you need to use a server name or ip instead of localhost on the app.config file to access it externally.
Do you have any antivirus or other firewall blocking requests from Service Studio?

Regards,
João Rosado
OMG

Ok, so I have been developing the wcf from visual studio on the outsystems server but developing outsystems from service studio on my laptop.  I opened service studio on my Outsystems server and did it there - NO PROBLEM.  THANK YOU SO MUCH!!!

So next step will be working with the wcf through windows service to see if it still does the 30 second kill on the connection.  Hopefully not!

Actually I would say the import working from the service studio on the outsystems server but not on the service studio on my laptop could be a big issue.  It "should" have worked from either location as I am not really doing anything "local" on my laptop.
Hehe good to know that you managed to get it to work.

Like I said, it does work remotely, but you can't setup it as "localhost". If you replace the localhost part with your server name or Ip address in both app.config and on the url that you are using to import it will work remotely.

Regards,
João Rosado
Hi Joao,
Liked your expalination , i am also veru curious about consuming WCF service from Service Studio but my wcf service is hosted using  NET TCP BINDING .
Can u plse give me some idea to consume a wcf service with NET TCP BINDING.
Joao,

Now that you got me to the point that I have writing code to getting it running in a windows service to consuming that windows service in Outsystems working - one more question which I am going to start investigating on Monday.  I want there to only be 1 instance of this windows service running (therefore only 1 connection from my Outsystems server to the device in the field).  The idea being in the onstart override I create a connection from the Outsystems pc to the field device and then from then on I just make a check at the start of any data read/writes to make sure the connection is still open and then read/write the data.  If I do have to reopen the connection I am going to have Outsystems email me so I will know.  I know in other code examples I have seen them use something called a singleton (class or function not sure) to make sure there is only 1 thread and hence 1 persistant instance of the code.  Do I still need to implement the singleton (or whatever I need to implement) as its running in a windows service (there is only 1 service running) or when I go in to make my code, do I need to make provisions in the code such that if there are multiple instances of the Outsystems webpage active at 1 time it will keep only 1 instance of the code I am going to write for the windows service and therefore only 1 connection between the Outsystems pc and the device in the field I am reading/writing data for?

Again - the reason this is important is that I want transmission of the data between the pc and the field device to be quick and if it has to open the connection, that adds about 5-8 seconds to the time to read/write.  Therefore I want to have 1 instance of the code active which when it starts up (or at the beginning of any read/write if the connection is lost) and then from that point forward it will just read/write the data using that connection which is fast (less than 1 second).

Thank you for all your help!!
Hi Pramod,

For that you will need to import in an extension.
(For the time being) Service Studio will only work on WCF with basicHttpBinding,

Regards,
João Rosado