Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Access WCF REST service through Netduino plus


  • Please log in to reply
3 replies to this topic

#1 Johnious

Johnious

    New Member

  • Members
  • Pip
  • 2 posts

Posted 27 August 2012 - 10:24 AM

Hello everybody

I have read couple of posts in this forum with respect to this subject but i am facing problems that is why i decided to ask you once more. I am new to netduino and MF and i want your advices. I have created a WCF web service that i would like to access it from netduino in order to record my temperature readings from a sensor. I would prefer if i could use no 3rd party framework and i would like if it is possible to give me some hints for the code. First of all i would like to know if i can access REST WCF services from netduino?
My netduino code is:


using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using System.Net.Sockets;
using System.IO;
using System.Text;




namespace NetduinoPlusApplication1
{
    public class Program
    {
        public static void Main()
        {
            
            // write your code here
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            var sw1 = new InputPort(Pins.ONBOARD_SW1,false,Port.ResistorMode.Disabled);
            while (true)
            {
                if(!sw1.Read())
                {
                    led.Write(!led.Read());
                    Thread.Sleep(500);
                    string message = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">23</string>"; 
                    byte[] byteArray = UTF8Encoding.UTF8.GetBytes(message);




                    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://10.1.8.131/TemperatureService/ShowTemperature.svc/GetTemperature/56"); 
                    myReq.Method = "GET"; 
                    HttpWebResponse WebResp = (HttpWebResponse)myReq.GetResponse();

                }

            }
        }

    }
}


According to my WCF service when i write (http://localhost/Tem...tTemperature/42) in browser i get a string as output with the temp. that i recorded i.e. 42 deg. of celcius recorded OK.

The problem that i am facing is that when i run the code in netduino there is nothing after the GetResponse i.e. the netduino freezes. How can i get the output from the WCF web service?

Thank you in advance.

Edited by Stefan, 27 August 2012 - 11:09 AM.
Added [code] tags


#2 Johnious

Johnious

    New Member

  • Members
  • Pip
  • 2 posts

Posted 27 August 2012 - 11:43 AM

One more thing to mention is that sometimes the code works fine but after a while it freezes and i cannot further access the part of code by pressing the Switch button. It seems that something freezes my netduino after first successful access the service. This does not work again after unplug and plug again.

#3 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 27 August 2012 - 01:57 PM

I looks like you are doing it right. What firmware version are you running? I would strongly encourage using the new release with QFE2 because a lot of networking issues are supposedly fixed. Also, I would try calling it as shown in this post and see if it works for you...

-Valkyrie-MT

#4 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 28 August 2012 - 11:23 AM

Have you tried using the HTTP client in the Netmf Toolbox?

I have used that with great success to communicate with WCF, and other rest based web services (Created a big red button which when pressed created a DNS entry using the Rackspace Cloud DNS API, so the boss could feel important on go live day ;))


Nak.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.