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

WCF Rest Service Trouble


  • Please log in to reply
4 replies to this topic

#1 cbcurtis

cbcurtis

    New Member

  • Members
  • Pip
  • 3 posts

Posted 09 December 2012 - 09:06 PM

I've been trying to get my netduino plus to call a WCF service and having no luck.

I've stripped down the service code to the bare minimum that I can and still having issues and wonder if anyone else can take a look.

I have gotten the server code in "Getting Started with the Internet of Things" appendex working, but really want to write WCF services. I had some trouble earlier till I opened up my port (8080) to allow the netduino to run properly with that code.

Setup, netduino plus plugged into the network switch, also plugged into USB on my development computer.

I feel I must be making some really basic mistake. Thanks for any assistance,
Cris


Netduino code:
namespace WCFTest
{
    using System.Net;
    public class Program
    {
        public static void Main()
        {

            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://172.16.0.15:8080/Service1.svc/GetData/1");
            myReq.Method = "GET";
            HttpWebResponse WebResp = (HttpWebResponse)myReq.GetResponse();
        }

    }
}
WCF Service Code:

IService1.cs
namespace NetduinoWCF
{
    using System.ServiceModel;
    using System.ServiceModel.Web;

    [ServiceContract]
    public interface IService1
    {
        [WebGet(UriTemplate = "GetData/{value}")]
        [OperationContract]
        string GetData(string value);

    }
}
Service1.svc.cs
namespace NetduinoWCF
{
    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return "0";
        }
    }
}
Web.config
<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>


  <system.serviceModel>
    <services>
      <service name="NetduinoWCF.Service1" behaviorConfiguration="ServiceBehavior">
        <endpoint address="" binding="webHttpBinding" contract="NetduinoWCF.IService1" behaviorConfiguration="web"></endpoint>
      </service>
    </services>
    
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

Edited by Chris Walker, 09 December 2012 - 10:18 PM.
added [code][/code] tags


#2 MarkNic

MarkNic

    Member

  • Members
  • PipPip
  • 22 posts

Posted 10 December 2012 - 03:21 PM

Cris, Could you narrow down your problem? What is/isn't working? Is it on the service side, is the netduino code throwing an exception or something else? Mark

#3 cbcurtis

cbcurtis

    New Member

  • Members
  • Pip
  • 3 posts

Posted 10 December 2012 - 05:05 PM

I'm running the wcf service in visual studio debug mode in visual studio 2012.
I'm running the netduino in debug mode in visual studio 2010.

Both on same computer.



At the HttpWebResponse WebResp = (HttpWebResponse)myReq.GetResponse(); the netduino stops on that line (for a long time, sometimes never recovering).
I believe the error I usually get is 10053? I was getting a similar error before due to ports being blocked, with a different sample application but have solved that issue.


I'll upload the exception results later tonight when I get back home.


Thanks for looking,

Cris

#4 ErikN

ErikN

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts
  • LocationNew York, NY

Posted 10 December 2012 - 09:54 PM

I'm running the wcf service in visual studio debug mode in visual studio 2012.
I'm running the netduino in debug mode in visual studio 2010.

Both on same computer.


While your VS instances are on the same computer, you Netduino is an external device. Usually VS doesn't not allow remote clients to connect to services it is hosting directly. I'm unsure if this is a setting that can be changed in Visual Studio directly.
I know you mentioned unblocking ports - is this from within VS or a firewall on your host computer? If it's a firewall, then VS itself is denying the connection attempt since it's coming from a client external to itself.

I really test this you'll have to publish your WCF service to an IIS virtual application or see if Visual Studio can be set to permit external connection requests.

#5 cbcurtis

cbcurtis

    New Member

  • Members
  • Pip
  • 3 posts

Posted 12 December 2012 - 03:13 AM

Thanks for your advice. I'm up and running now. Experienced quite a lot of issues with IIS7 setup on this computer during the process (aspnet_regiis... etc...), so I did the smart thing and tested the access to the site from another computer till it worked. It's amazing the thrill of victory that you get from a blinking led signaling success after hours of frustration.




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.