Running DPWS Server on a gadgeteer: how can I do it?

Hi all,

We recently bought some Gadgeteers (FEZ Spider and FEZ Hydra kits) because for our research we are interested in Web Services and especially in DPWS (Device Profile for WS). So far, we have worked with other devices running DPWS (Android devices, Raspberrys) and our idea is include in our scenario the Gadgeteers. Access and control the camera or the light sensor (just a couple of examples) exposed as services through WS is our challenge and the reason for which we bought these kits (they are supposed to implement DPWS in a almost native way, aren’t they?)

After this introduction just to make you understand what we want, I should say we are totally newbies not only with Gadgeteers but also with .NET MF programming (and in my case, with .NET in general) so, sorry in advance.

I started playing a little bit and get familiar with the toys (camera, sensors, leds…), and with some help(http://www.ghielectronics.com/community/forum/topic?id=11640&page=1), I got my Spider connected via Wifi.

Now, I want to start the DPWS part and for that my intention was reuse the code on HelloWorldServer_MF example included in the samples installed with MF4.2 SDK.

But when I deploy and debug the code, i get an error like that:

    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (2) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
    #### System.Net.Dns::GetHostEntry [IP: 0008] ####
    #### System.Net.IPAddress::GetDefaultLocalAddress [IP: 0049] ####
    #### Ws.Services.Transport.WsNetworkServices::GetLocalIPV4Address [IP: 0003] ####
    #### Ws.Services.Binding.UdpTransportBindingElement::.ctor [IP: 0011] ####
    #### Ws.Services.Transport.UDP.WsUdpServiceHost::.ctor [IP: 0037] ####
    #### Ws.Services.Transport.UDP.WsUdpServiceHost::.cctor [IP: 0003] ####
    #### SocketException ErrorCode = -1
    #### SocketException ErrorCode = -1
Excepción del tipo 'System.Net.Sockets.SocketException' en Microsoft.SPOT.Net.dll
    #### SocketException ErrorCode = -1
    #### SocketException ErrorCode = -1

I’m not the only one with this problem (http://www.ghielectronics.com/community/forum/topic?id=8889) and some other mentioned a problem with UDP (http://www.ghielectronics.com/community/forum/topic?id=10337) but after read for a while I’m not sure if it is already fixed and I’m can not find the solution to my problems.

Please, if anyone can help me or give me some code to do what I expect to do I will be sooo happy. Think of me like a dummy, not like an advance user please :slight_smile:

I’m working with the last firmware on my Spider (I update it a couple of hours ago, 4.2.9 firm. I think) and .NETMF 4.2.

Thank you very much.

DPWS is NOT for the faint of heart. IE that probably means if we think of you as “a dummy”, we’d probably steer you away from DPWS. But since you have already some experience with it outside the NetMF world, you can probably battle through these.

So lets take this all a step at a time.

First, the post http://www.ghielectronics.com/community/forum/topic?id=8889&page=4 was 6 days ago, and we haven’t seen the new “fixed” SDK that Gus mentioned yet (it’s been hinted that we’re days not weeks or months away from release, but as with any testing you may find issues even at this late stage), so I don’t know how much value there is in diagnosing this further; you will need the new SDK. But here’s the questions I’d ask…

Where in your code do you hit the exception you quote? That might help us understand what’s going on when it occurs. If you look at the sequence of calls in the exception, you can see it’s calling at some point the GetHostEntry, which implies to me it’s possibly doing a DNS lookup. Have you broken down the problem and confirmed you can do other things on the network (HTTP GET request for instance) so you know the network configuration you’re using is successful? Have you then also broken down the network aspect by looking at what actually happens on your network using network monitor? What comms can you see going on?

I know these aren’t answers, but hope they help you out

DPWS requires multicast, which was fixed but the SDK is not out yet. It shouldn’t be too long before it is out.

But like Brett said, DPWS is not simple.

First of all, thank you Gus and Brett for your answers.

Maybe “dummy” isn’t the more adequate word for define myself, I just meant that please not take for obvious steps, code or other things that are granted for advanced users like you but not for me, totally new user with .NET, Visual Studio and Gadgeteers.

About my exeption, this is generated at the very beggining of the execution. Actually, after make a number of test, I’m pretty convinced that it is raised when I include either the MFWsStack or the MFDpwsDevice libraries in the references of the projects, even if I’m not using them in the code.

Given that there are multicast problems not already fixed, let’s try my connectivity with the Spider is working well.

So far, I have the Wifi module connected to my WLAN:

if (!wifi_RS21.Interface.IsOpen)
                wifi_RS21.Interface.Open();

            if (!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled)
                wifi_RS21.Interface.NetworkInterface.EnableDhcp();

            NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);

            wifi_RS21.Interface.WirelessConnectivityChanged += new WiFiRS9110.WirelessConnectivityChangedEventHandler(WirelessConnectivityChanged);
           WiFiNetworkInfo[] ScanResp = wifi_RS21.Interface.Scan("(SSID_OF_MY_WLAN");

            if (ScanResp != null && ScanResp.Length > 0)
            {
                wifi_RS21.Interface.Join(ScanResp[0], "(MY_PASS)");
            }

        void WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
        {
            Debug.Print("WirelessConnectivityChanged event!");
            Debug.Print("Connected: " + e.IsConnected);
            Debug.Print("IP Address : " + wifi_RS21.Interface.NetworkInterface.IPAddress);
        }

I can see my new IP address on the debug so I’m connected.

So, let’s try a simple HTTP client. Where can I find some code to test this? Write from scratch is hard for me right now and port the samples codes included with MF4.2 to Gadgeteer code is sometimes not so straightforward for a newbie.

Thank you very much again.

Hi again,

After a few days I have checked connectivity on the Spider and I am able to run a web server (HTTP) and interact with ot through the browser or other ways. So I am connected to the internet.

But still WebServices problems when I initialize MFWsStack or the MFDpwsDevice libraries as I mentioned in a previous post.

Could you help me with this? (just to confirm is problem of the UDP multicast and not mine)

After connect my Spider via Wifi, I try to run DPWS in this way:

        public void initDPWS()
        {

            // Initialize the binding
            //Guid g = Guid.NewGuid();
            string guid = "urn:uuid:18571766-87df-06e2-bb68-5136c48f483f";

            ProtocolVersion version = new ProtocolVersion11();

            // ProtocolVersion10 can be used only if the corresponding HelloWorldClient_WCF application
            // uses a custom binding with Soap12WSAddressingAugust2004 text message encoding.
            //ProtocolVersion version = new ProtocolVersion10();

            Device.Initialize(new WS2007HttpBinding(new HttpTransportBindingConfig(guid, 8084)), version);

            // Set device information
            Device.ThisModel.Manufacturer = "Microsoft Corporation";
            Device.ThisModel.ManufacturerUrl = "http://www.microsoft.com/";
            Device.ThisModel.ModelName = "SimpleService Test Device";
            Device.ThisModel.ModelNumber = "1.0";
            Device.ThisModel.ModelUrl = "http://www.microsoft.com/";
            Device.ThisModel.PresentationUrl = "http://www.microsoft.com/";

            Device.ThisDevice.FriendlyName = "HelloWorldService";
            Device.ThisDevice.FirmwareVersion = "alpha";
            Device.ThisDevice.SerialNumber = "32345678";

            // Add a Host service type
            Device.Host = new HelloWCFService(version);

            // Add Dpws hosted service(s) to the device
            Device.HostedServices.Add(new IServiceHelloWCF(new ServiceHelloWCFImplementation()));

            // Set this device property if you want to ignore this clients request
            Device.IgnoreLocalClientRequest = false;

            // Turn console messages on
            Console.Verbose = true;

            System.Ext.Console.Write("Start DPWS device service with endpoint address: '" + Device.EndpointAddress + "'");

            ServerBindingContext ctx = new ServerBindingContext(version);

            // Start the device
            Device.Start(ctx);
        }

This code comes from the HelloWorldServer_MF sample installed on the Documents\Microsoft .NET Micro Framework 4.2\Samples folder. On the project, I have also the files generated automatically describing and providing the functionallity of the WebService (ServiceHelloWCF.cs, ServiceHelloWCFHostedService.cs, ServiceHelloWCFImpl.cs)

But still same error of my first post. :frowning: Any idea?

@ andre.m - Thank you. A couple of questions:
[ul]Is my problem related to that issue for sure? Because I’m not totally convinced (that’s why I asked again, in the first answer of Brett he also asked me to make tests to check where was the error)[/ul]
[ul]Is there any option to downgrade the firmware to any version in which DPWS worked?[/ul]

4.1 framework examples apparently have DPWS working. I have no personal experience with that, but feel confident telling you that if you went back to 4.1 firmware and targeted the 4.1 framework in your app, you should not see an issue.

The reason why I talked about those tests was explicitly in case you thought it was worth continuing - I didn’t think it was worth progressing. In fact, I said “you will need the new SDK”, there is no question in that. But the testing thoughts were there because they’re just breaking down the problem into more manageable chunks, and will totally be required once the new SDK comes out.

@ Brett - Thank you.

Actually I understand your point because as I said I’m not sure about UDP multicast is the only problem according to the errors I get :


 #### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
    #### System.Net.Dns::GetHostEntry [IP: 0008] ####
    #### System.Net.IPAddress::GetDefaultLocalAddress [IP: 0049] ####
    #### Ws.Services.Transport.WsNetworkServices::GetLocalIPV4Address [IP: 0003] ####

It seems like Gadgeteer doesn’t know what is the IP (configured by hand at the beginning of my code). In the MF NET code sample they use:

            NetworkInterface ni;

            // Wait for DHCP (on LWIP devices)
            while (true)
            {
                ni = NetworkInterface.GetAllNetworkInterfaces()[0];

                if (ni.IPAddress != "0.0.0.0") break;

                Thread.Sleep(1000);
            }

But I can’t not do this on the Gadgeteer because it doesn’t work.

There is a strange thing: even with the exeptions it seems like DPWS device starts running:

Start DPWS device service with endpoint address: 'urn:uuid:18571766-87df-06e2-bb68-5136c48f483f'

and I’m able to “see it” from a DPWS explorer software but not get more metadata (Device model, manufacturer, services hosted…) . This problem is probably in line with multicast (Probe and Hello messages of DPWS use it)

So, any help with the first part? Thank you again.

@ Brett - About the downgrade, do I need to downgrade also the firmware on my Spider or it is independient and I also need to make a new app with target 4.1? (sorry if it is a stupid question)

I have another problem with this: when I start a new project on Visual Studio, I can choose Gadgeteer 4.2 or Gadgeteer 4.1 but when I choose the last one, in the Program.gadgeteer file (the schematic where you connect in a graphical way all the modules and board) has no any module or board to add! It’s empty.

I can write the code, is not a big problem but I don’t know if it will work.

And sorry for the insistence but that’s not for fun, it’s my work in research right now (build a real scenario with DPWS devices) so it is worth progressing on it.

Thank you.

I suggest you wait for the SDK coming out in few days and give it a try. It fixes a problem in networking.

Also, 4.1 is more stable but we do not support gadgeteer in 4.1

@ Gus - Thank Gus.

OK, I can understand you are not supporting 4.1 anymore but I’d like to try, what are the steps to downgrade the Spider and write apps for it in Visual Studio?

Keep everything the same, except download GHI’s optional 4.1 SDK from support page.

From there, you can upload the 4.1 firmware (from 4.1 SDK folder) on your spider.

You will still use NETMF 4.2 QFE2 on your PC but when you create a project, go under properties and change its target to NETMF 4.1

Note that this will be switched to NETMF 4.3 in couple days but 4.1 is still supported in-within 4.3!

@ fprado The error in your first post happenevwhen you add a reference to MFWsStack. One of the static classes makes a call to GetDefaultLocalAddress before any network code runs. This goes away if you set a static ipadress. From what I can tell you can ignore the error if your default adress is 0.0.0.0 and you later change it with DHCP. The 0.0.0.0 causes the address to get rechecked when you call device start

The udp error occurs when you call device start and the discovery service tries to bind to a udp multicast address. Fingers crossed this will be fixed shortly

@ fprado the new sdk fixes DPWS. You still get the annoying exception at startup which I mentioned in the previous post, but it can definitely be ignored.

@ NickP Thank you. SDK 4.3 you mean? Where can I find more information about it?

http://www.ghielectronics.com/community/forum/topic?id=11849 is the post for the latest GHI SDK that addresses this, and it’s only 4.2 (although uses the 4.3 raw SDK to get VS2012 support; if you don’t need that, follow the instructions http://www.ghielectronics.com/support/.net-micro-framework for VS2010 )

I have installed the GHI Software Package v4.2 (in Visual Studio 2010) and upgrade the firmware on my Spider (4.2.10.1) but I still get the same error :frowning:

    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (2) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
    #### System.Net.Dns::GetHostEntry [IP: 0008] ####
    #### System.Net.IPAddress::GetDefaultLocalAddress [IP: 0049] ####
    #### Ws.Services.Transport.WsNetworkServices::GetLocalIPV4Address [IP: 0003] ####
    #### Ws.Services.Binding.UdpTransportBindingElement::.ctor [IP: 0011] ####
    #### Ws.Services.Transport.UDP.WsUdpServiceHost::.ctor [IP: 0037] ####
    #### Ws.Services.Transport.UDP.WsUdpServiceHost::.cctor [IP: 0003] ####
    #### SocketException ErrorCode = -1
    #### SocketException ErrorCode = -1
Excepción del tipo 'System.Net.Sockets.SocketException' en Microsoft.SPOT.Net.dll
    #### SocketException ErrorCode = -1
    #### SocketException ErrorCode = -1

Anyway, DPWS seems to start working on my device but when I try to discover its services (using DPWS Explorer (http://ws4d.e-technik.uni-rostock.de/dpws-explorer/) I get a new error on the debug console of VS:

    #### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (12) ####
    #### Message: 
    #### Dpws.Device.Mex.DpwsWsxMetdataResponse::GetResponse [IP: 0071] ####
    #### Dpws.Device.Mex.DpwsDeviceMexService::Get [IP: 0048] ####
    #### System.Reflection.MethodBase::Invoke [IP: 0000] ####
    #### Dpws.Device.Services.DpwsHostedService::ProcessRequest [IP: 003f] ####
    #### Dpws.Device.Services.DpwsHostedService::Ws.Services.IWsServiceEndpoint.ProcessRequest [IP: 0014] ####
    #### Ws.Services.Transport.HTTP.WsHttpMessageProcessor::ProcessRequestMessage [IP: 00de] ####
    #### Ws.Services.Transport.HTTP.WsHttpMessageProcessor::ProcessRequest [IP: 0051] ####

Any help?

@ fprado -

Did you use mfsvcutil to generate your classes or did yu that yourselves ?

@ LouisCpro - I used the sample code included in the HelloWorldServer_MF project in /Documents/Microsoft .NET Micro Framework 4.2/Samples

OK,

If you did not tray to make any modification to the project, it definitively means to wait for the new SDK…