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 Service Host issues (.net MF 4.3)

wcf host .net MF 4.3

  • Please log in to reply
1 reply to this topic

#1 bvince05

bvince05

    New Member

  • Members
  • Pip
  • 3 posts
  • LocationPhoenix, AZ

Posted 31 March 2015 - 05:06 PM

Hello everyone,

 

I'm absolutely loving my Netduino Plus 2!  But I am having some serious trouble trying to get a WCF service hosted on my hardware.  As I read the .Net Micro Framework 4.3 SDK docs, it appears that most of the difficult stuff like worrying about WSDL files/discovery/etc are taken care of under the hood (which is great and how it's done in full .net).  That said, I cannot seem to get my service up and running...or find any examples of people doing the same thing in this specific version of .Net MF.  

 

My service is here:

[ServiceContract]
    public interface IBriansWCFService
    {
        [OperationContract]
        void LED1(bool value);

        [OperationContract]
        void SendSerialMsg(string message);

    }


    public class MyService : DpwsHostedService, IBriansWCFService
    {

        private MySerialPort sPort;
        private MyBoard mBoard;

        public MyService(ProtocolVersion pVersion)
            : base(pVersion)
        {
            sPort = new MySerialPort();
            mBoard = new MyBoard();

            
        }



        public void LED1(bool value)
        {
            throw new NotImplementedException();
        }

        public void SendSerialMsg(string message)
        {
            throw new NotImplementedException();
        }
    }

As you can see, I developed a simple DpwsHostedService.  This part, for me, was straight forward as it is almost identical to how you develop services in full .NET.  

 

 

It's the next part that is confusing (a little bit ambiguous in the docs) and where I believe I'm having my problems.


 public class Program
    {
        public static void Main()
        {
 
            //instantiate protocol version to use everywhere it needs one (alot of places apparently)
            ProtocolVersion11 protocolVer = new ProtocolVersion11();
 
            //instantiate my service and provide protocol version as DpwsHostService requires it
            MyService mService = new MyService(protocolVer);
            
            Debug.Print(Device.IPV4Address);
 
            //this line throws a null pointer exception!
            //Device.HostedServices.Add(mService);
 
 
            //initialize my Device stack with protocol version and HTTP binding
            Device.Initialize(new WS2007HttpBinding(), protocolVer);
            
            //start my Device's stack
            Device.Start(new Ws.Services.Binding.ServerBindingContext(protocolVer, new Ws.Services.Binding.BindingProperty[0] ));
 
            Debug.Print(Device.IPV4Address);
            
 
        }
 
    }

First, whenever I add my instantiated service to the Device.HostedServices stack, it throws a null pointer exception...so I commented this out.  Once commented, if I try and execute the Device.start method, it throws another (but different) type of exception.

 

I was hoping that this community might be able to shed some light on what I'm missing and doing wrong.  This rally isn't far off from how you do this in full .NET and so I fell I'm missing something small but crucial.

 

Can you awesome people help me?

 

Thanks!



#2 bvince05

bvince05

    New Member

  • Members
  • Pip
  • 3 posts
  • LocationPhoenix, AZ

Posted 01 April 2015 - 10:32 AM

Ok, I've got an update...I was able to figure out why setting up my Device.Host was throwing exceptions.  But unfortunately, I'm still stuck on the Device.Start method as it asks for a ServerBindingContext which in turn asks for BindingProperties.  What are BindingProperties and how to I get access to these?  Creating BindingProperties requires you to know the name, container, and value which doesn't make sense to me :(.

Here is my updated Service:

[ServiceContract]
    public interface IBriansWCFService
    {
        [OperationContract]
        void LED1(bool value);

    }


    public class MyService : DpwsHostedService, IBriansWCFService
    {

        private MyBoard mBoard;

        public MyService(ProtocolVersion pVersion)
            : base(pVersion)
        {
            mBoard = new MyBoard();
                        
            ServiceTypeName = "BrianSimpleService";
            string sid = "urn:uuid:" + Guid.NewGuid().ToString();
            ServiceID = sid;
        }



        public void LED1(bool value)
        {
            mBoard.LED1 = value;
        }

    }

And here is my updated Main:

public static void Main()
        {

            WS2007HttpBinding binding = new WS2007HttpBinding();
            ProtocolVersion11 protocol = new ProtocolVersion11();
            
            Device.Initialize(binding, protocol);

            MyService mService = new MyService(protocol);
            
            Device.Host = mService;
            Device.IgnoreLocalClientRequest = true;

            Debug.Print(Device.IPV4Address);
            
            

            while (true)
            {
                try
                {
                    
                    Device.Start(new ServerBindingContext(protocol, (BindingProperty)binding.Elements.GetBindingProperty("")));
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message);
                    
                }
            }

I truly appreciate any help.  I've been banging my head against the wall on this for hours!

 

Thanks!







Also tagged with one or more of these keywords: wcf, host, .net MF 4.3

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.