Web services for RAPTOR

I have added a webservice to a project for the Raptor board. With MFDpwsDevice, MFDpwsExtensions, and MFWsStack the project successfully compiles (Studio says Runtime version v4.0.30319 and version 4.2 on all references). When I try to debug on the board it throws Error 1 below. So I commented out all WS code and just tried to add the reference MFWsStack that throws Error 2. No WS code…just the reference. When I remove the reference to MFWsStack the board works fine and I can see the board step through the code just fine.

Thanks!

Error 1

Exception System.Net.Sockets.SocketException - CLR_E_FAIL (2)

#### Message: 
#### Ws.Services.Transport.WsNetworkServices::GetLocalIPV4Address [IP: 0003] ####
#### Ws.Services.Binding.UdpTransportBindingElement::.ctor [IP: 0011] ####
#### Ws.Services.Transport.UDP.WsUdpServiceHost::.cctor [IP: 0003] ####
#### SocketException ErrorCode = -1

Error 2:

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI Premium NETMF v4.2 SDK\Assemblies\le\GHI.Premium.USBHost.dll’
‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Users\admin\documents\visual studio 2012\Projects\GadgeteerApp1\GadgeteerApp1\bin\Debug\le\GadgeteerApp1.exe’, Symbols loaded.
#### 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
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1

I would assume that the library you had to comment out so it works tries to get the local IP of the board on startup, which is not available for some reason.
Just because something complies does not mean that it will run.

The error seems to occur before managed code. Is there a default IP that needs to get set somewhere before adding references in Visual Studio to the MFDpws components?

I mention the other code being deployed to the board and running only to illustrate the board is working otherwise. I can even get the IP address if I initiate the wifi module.

Thanks!

Generally there are two ways to initialize network:
In code or via FEZConfig tool.
So far I alawys used in code init, which would not help you if the lib accesses network before any managed code.
Have you looked for DWPS samples in Codeshare/Forum, it’s discussed from time to time.

I just looked at the IPs in the Fez Config Tool. Built in Ethernet, ENC28, and RS910 all have a static ip address that is not null.

Does anyone have a raptor board that they could try adding the MFWsStack reference too? No code required to fail for me just adding the reference and trying to debug causes the issue.

Hi,
I just tried it with ENC28 Module on Socket 1. Program with no Code runs without error message. The three references were added.

Edit:
Sorry did not look exactly I got the following exception:
#### 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
Eine Ausnahme (erste Chance) des Typs “System.Net.Sockets.SocketException” ist in Microsoft.SPOT.Net.dll aufgetreten.
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1

But perhaps you can ignore the exception an initialize the ENC28 module as usual.

Is it possible to ignore exceptions thrown before it actually loads the code on the board?

Would it be safe to say that DPWS is not supported on Raptor?

Thanks…I am very new to mf.

Set a break point in the 1st line of your code.
If it is hit (even that the exception is there) then it should work.
It’s not nice that the exception is thrown, but as long as the app runs :slight_smile:

OK…Turned on C++ exceptions and get error1. But I can then continue into the code…Yes!

error1
An exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net and wasn’t handled before a managed/native boundary

Do you think this exceptions will prevent features of Web services from functioning properly?

Thank You!

Best way to find out is trying ;D

Just made this little test, seems to work despite the exception


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using GHI.Premium.Net;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace Raptor_Test_MFDPWS
{
    public partial class Program
    {
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            ethernet_ENC28.Interface.CableConnectivityChanged += Interface_CableConnectivityChanged;
            ethernet_ENC28.Interface.NetworkAddressChanged += Interface_NetworkAddressChanged;
            ethernet_ENC28.Interface.Open();
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28.Interface);

           // if (!ethernet_ENC28.Interface.NetworkInterface.IsDhcpEnabled)
            ethernet_ENC28.Interface.NetworkInterface.EnableDhcp();
            //ethernet.Interface.NetworkInterface.EnableStaticIP(IPv4Address, SubnetMask, GatewayAddress);
            Thread.Sleep(100);
            Debug.Print("Waiting for IP address ... ");
            Thread.Sleep(100);
            try
            {
                Debug.Print("Actual Network settings:");
                Debug.Print("IP Address: " + ethernet_ENC28.Interface.NetworkInterface.IPAddress);
                Debug.Print("Subnet Mask: " + ethernet_ENC28.Interface.NetworkInterface.SubnetMask);
                Debug.Print("Default Gateway: " + ethernet_ENC28.Interface.NetworkInterface.GatewayAddress);
                Debug.Print("Number of DNS servers:" + ethernet_ENC28.Interface.NetworkInterface.DnsAddresses.Length);
                for (int i = 0; i < ethernet_ENC28.Interface.NetworkInterface.DnsAddresses.Length; i++)
                    Debug.Print("DNS Server " + i.ToString() + ":" + ethernet_ENC28.Interface.NetworkInterface.DnsAddresses[i]);
                Debug.Print("\r\n\r\n");
            }
            catch 
            {
                Debug.Print("Could not print settings");
            };
        }

        void Interface_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("Interface_NetworkAddressChanged");
            Debug.Print("New address for the Network Interface ");
            Debug.Print("Is DhCp enabled: " + ethernet_ENC28.Interface.NetworkInterface.IsDhcpEnabled);
            Debug.Print("Is DynamicDnsEnabled enabled: " + ethernet_ENC28.Interface.NetworkInterface.IsDynamicDnsEnabled);
            Debug.Print("NetworkInterfaceType " + ethernet_ENC28.Interface.NetworkInterface.NetworkInterfaceType);
            Debug.Print("Network settings:");
            Debug.Print("IP Address: " + ethernet_ENC28.Interface.NetworkInterface.IPAddress);
            Debug.Print("Subnet Mask: " + ethernet_ENC28.Interface.NetworkInterface.SubnetMask);
            Debug.Print("Default Gateway: " + ethernet_ENC28.Interface.NetworkInterface.GatewayAddress);
            Debug.Print("Number of DNS servers:" + ethernet_ENC28.Interface.NetworkInterface.DnsAddresses.Length);
            for (int i = 0; i < ethernet_ENC28.Interface.NetworkInterface.DnsAddresses.Length; i++)
                Debug.Print("DNS Server " + i.ToString() + ":" + ethernet_ENC28.Interface.NetworkInterface.DnsAddresses[i]);
            Debug.Print("------------------------------------------------------");
            
        }
        void Interface_CableConnectivityChanged(object sender, EthernetENC28J60.CableConnectivityEventArgs e)
        {
          //  throw new NotImplementedException();
        }
    }
} 

RoSchmi…Thanks! That looks extremely useful.

Currently I am getting: System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net and wasn’t handled before a managed/native boundary

When I try to run either version of the code below:

  //ProtocolVersion version = new ProtocolVersion11();
   ProtocolVersion version = new ProtocolVersion10();
   Device.Initialize(new WS2007HttpBinding(new HttpTransportBindingConfig(guid, 8084)), version);

RoSchmi…I used your:

ethernet_ENC28.Interface.Open();
NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28.Interface);

// if (!ethernet_ENC28.Interface.NetworkInterface.IsDhcpEnabled)
ethernet_ENC28.Interface.NetworkInterface.EnableDhcp(); 

AND IT NO LONGER THROWS CONTINUOUS EXCEPTIONS!

THANK YOU…with caps = extreme emphasis.

I’m glad that I could help.
Took your question as a chance to try network initialization on my new raptor.
Don’t know anything about Web Services.