Main Site Documentation

DPWS Device.Start exception


#1

I am trying to host a DPWS service on my Gadgeteer device that will be consumed by a WCF client. I have everything working when I use the 4.1 Emulator, but when I try to deploy the code to the Gadgeteer I receive the folloiwng error (when debugging the deployment):


 #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####

 #### Message:

 #### Microsoft.SPOT.Net.SocketNative::sendto [IP: 0000] ####

 #### System.Net.Sockets.Socket::SendTo [IP: 0022] ####

 #### System.Net.Sockets.Socket::SendTo [IP: 000a] ####

 #### Dpws.Device.Discovery.DpwsDiscoGreeting::SendGreetingMessage [IP: 0087] ####

 #### Dpws.Device.Device::Start [IP: 0020] ####

 #### Program::startMyService [IP: 00a6] ####

 #### Program::ProgramStarted [IP: 0076] ####

 #### Program::Main [IP: 0015] ####

 #### SocketException ErrorCode = 10049

 #### SocketException ErrorCode = 10049

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll

 #### SocketException ErrorCode = 10049

An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll

I have also tried the sample code (HelloWorldServer_MF) that comes with the 4.1 SDK but I receive the same error. Is this related to the Gadgeteer? If there was a 4.2 Gadgeteer firmware out I would try 4.2 to see if the problem is still present … thanks!

Update: I found this post that states there is a possible fix to DPWS but the download link is broken:
http://www.tinyclr.com/forum/1/2224/


#2

Doing some more digging I found what appears to be the same problem from this post:
http://www.tinyclr.com/forum/10/2057/

Also, I have posted this question on the netmf forums:
http://www.netmf.com/forum/default.aspx?g=posts&t=2258

Can anyone confirm if Sander Marsman was able to get this fixed with the code that GHI sent him?

I would be more than happy to test out any code that may fix this problem!


#3

All I personally know is that DPWS is rarely used and it is possible that it has some issues. Also, NETMF4.2 did some fixes in this area, which is planned to be available Q1/2012.


#4

Hi There,
i just decided to play with the DPWS so i loaded the HelloWorldServer_MF sample that came with the .netMD SDK… which worked great on the emulator but when taken to the spider i got the exception error… and the reason for the error was simply the WRONG IP Address…
in the sample code they were looking to 0.0.0.0 but the GHI Spider for some reason has a default IP set to 192.168.1.200 which i recommend GHI to replace by 0.0.0.0… maybe it is something we can do here… anyway: the current CODE:


        while (true)
            {
                ni = NetworkInterface.GetAllNetworkInterfaces()[0];   
                if (ni.IPAddress != "0.0.0.0") break;

                Thread.Sleep(1000);
            }

must be replaced with :


        while (true)
            {
                ni = NetworkInterface.GetAllNetworkInterfaces()[0];
                ni.EnableDhcp(); //Enabled DHCP...
                if (ni.IPAddress != "0.0.0.0" & ni.IPAddress != "192.168.1.200") break; //Chekc for the default IP before you continue.

                Thread.Sleep(1000);
            }

once i did the above it worked great.

hope this can help…

Jay.


#5

You can set the default ip from mfdeploy.


#6

Thanks Jay Jay … Unfortunetly my setup does not include a router or hub that will assign a DHCP address and when I call EnableDHCP() I get an exception (I think it times out since there is not DHCP server).

However, there is good news! Someone posted a solution in the netmf forums (http://www.netmf.com/forum/default.aspx?g=posts&t=2258) that did solve my problem!!! I needed to call EnableStaticIP() like this:


NetworkInterface ni = NetworkInterface.GetAllNetworkInterfaces()[0];
ni.EnableStaticIP("192.168.1.200", "255.255.255.0", "192.168.1.100");

Not sure what magic this call does, but it allows me to run my DPWS service on the gadgeteer! Thanks all for the help, very much appreciated!


#7

You are welcome,
if you are using Gadgeteer like the spider, you may want to take advantage of the simplified code it offers:

like this


   void ProgramStarted()
        {
            ethernet.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(ethernet_NetworkUp);
            ethernet.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(ethernet_NetworkDown);

            ethernet.UseStaticIP("192.168.1.200", "255.255.255.0", "192.168.1.100");

}
        void ethernet_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("Network down!");
        }

        void ethernet_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("Network up!");
            Start();
        }

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

            // ProtocolVersion10 can be used only if the corresponding HelloWorldClient_WCF application
            // uses a custom binding with Soap12WSAddressingAugust2004 text message encoding.
            //ProtocolVersion version = new ProtocolVersion11();
            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/";


.......... the rest from the sample HelloWorldServer_MF
}



Hope this helps.
Jay,