Main Site Documentation

GHI Raptor w/ENC28 connecting to WCF via DPWS


#1

I am having difficulty getting my Raptor with ENC28 to connect to a simple WCF Service.

I am not sure what all code is relevant to post, as there is quite a bit when I add in all of the WCF. I can make the solution available.

My main program.cs

using System;
using Microsoft.SPOT;
using GHI.Premium.Net;

using Gadgeteer.Networking;
using Ws.Services;
using Ws.Services.Binding;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using tempuri.org;

namespace RaptorNetwork
{
    public partial class Program
    {
        private IService1ClientProxy _proxy;
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");


            InitializeNetwork();


            button.TurnLEDOn();
            button.ButtonPressed += button_ButtonPressed;
        }

        void Program_ResponseReceived(HttpRequest sender, HttpResponse response)
        {
            if (response.StatusCode == "200")
            {
                Debug.Print(response.Text);
            }
            else
            {
                Debug.Print("HTTP-Response: " + response.StatusCode);
            }

        }

        #region Events
        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            Debug.Print("Button Pressed");
            CallServiceTest();
        }

        private void CallServiceTest()
        {
            WebClient.GetFromWeb("http://www.newegg.com/").ResponseReceived += Program_ResponseReceived;

            GetData getData = new GetData
            {
                value = 1112
            };
            GetDataResponse getDataResponse = _proxy.GetData(getData);

            Debug.Print(getDataResponse.GetDataResult);
        }

        void Interface_CableConnectivityChanged(object sender, EthernetENC28J60.CableConnectivityEventArgs e)
        {
            Debug.Print("Cable " + (e.IsConnected ? "is " : "is not ") + "connected.");
        }

        void Interface_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("Network Address Changed.");
            Debug.Print("IP Address: " + ethernetENC28.Interface.NetworkInterface.IPAddress);
            if (ethernetENC28.Interface.IsActivated)
            {
                InitializeService();
                CallServiceTest();
            }
        }

        #endregion

        #region Initializers
        private void InitializeNetwork()
        {

            ethernetENC28.Interface.Open();

            ethernetENC28.Interface.NetworkInterface.EnableDhcp();
            ethernetENC28.Interface.NetworkInterface.EnableDynamicDns();

            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernetENC28.Interface);

            ethernetENC28.Interface.NetworkAddressChanged += Interface_NetworkAddressChanged;
            ethernetENC28.Interface.CableConnectivityChanged += Interface_CableConnectivityChanged;
        }

        private void InitializeService()
        {
            WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig(new Uri("http://vmsp1.idontexist.local:5598/Service1.svc/wsHttp")));
            _proxy = new IService1ClientProxy(binding, new ProtocolVersion11());

        }

        #endregion
    }
}

I can add more if anyone wants to see specific files.

when I make a call _proxy.GetData(getData); I am getting the following exception.

Exception Ws.Services.Faults.WsFaultException - 0x00000000 (5)

#### Message: 
#### Ws.Services.Faults.WsFault::ThrowFaultException [IP: 01fc] ####
#### Ws.Services.WsaAddressing.WsWsaHeader::ParseHeader [IP: 01d3] ####
#### Ws.Services.Encoding.TextMessageEncodingBindingElement::OnProcessInputMessage [IP: 01fc] ####
#### Ws.Services.Binding.BindingElement::ProcessInputMessage [IP: 0019] ####
#### Ws.Services.Binding.RequestChannel::ReceiveMessage [IP: 002c] ####
#### Ws.Services.Binding.RequestChannel::Request [IP: 0017] ####
#### tempuri.org.IService1ClientProxy::GetData [IP: 0047] ####
#### RaptorNetwork.Program::CallServiceTest [IP: 002a] ####
#### RaptorNetwork.Program::Interface_NetworkAddressChanged [IP: 003a] ####
#### GHI.Premium.Net.NetworkInterfaceExtension::NetworkChangeExtension_NetworkAddressChanged [IP: 0021] ####
#### GHI.Premium.Net.NetworkChangeExtension::OnNetworkChangeCallback [IP: 00ac] ####
#### GHI.Premium.Net.NetworkChangeExtension+NetworkChangeExtensionListener::OnEvent [IP: 000d] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####

A first chance exception of type ‘Ws.Services.Faults.WsFaultException’ occurred in MFWsStack.dll
An unhandled exception of type ‘Ws.Services.Faults.WsFaultException’ occurred in MFWsStack.dll
Uncaught exception
The thread ‘’ (0x7) has exited with code 0 (0x0).
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####
#### Message:
#### System.Text.UTF8Encoding::GetChars [IP: 0000] ####
#### Gadgeteer.Networking.HttpResponse::get_Text [IP: 0019] ####
#### Gadgeteer.Networking.HttpRequest::OnResponseReceivedEvent [IP: 0036] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type ‘System.OutOfMemoryException’ occurred in mscorlib.dll
Could not decode the requested data and create text

The thread ‘’ (0x9) has exited with code 0 (0x0).

Has anyone come across this error, or does it look familiar? I was not able to find anything relevant in my googling :slight_smile: or here on the forums.

Right now, the WCF service is hosted on an IIS * box that I have hosted on my network. Security is set up to allow anonymous connections and I can hit it without issue on a network-conected but non-domain joined computer, so I do not believe that it is IIS security or firewall.


#2

You’re doing something to use up all your memory. I suspect that your response is too large and its blowing up before the HttpResponse object can be created. Did you try with a known small response?


#3

Holy crap. I removed the line where I was doing the http request to newegg.com and I was still getting the first error.

Exception Ws.Services.Faults.WsFaultException - 0x00000000 (5)

It turns out that it WAS an issue with my WCF configuration. wsHttpBinding by default uses windows authentication. It was allowing anonymous connections, but they had to come from windows clients? I had to turn it off.

I had to add:


<bindings>
      <wsHttpBinding>
        <binding name="wsBinding">
          <security mode="None">
            <transport clientCredentialType="None" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="None" algorithmSuite="Default" />
          </security>

        </binding>
      </wsHttpBinding>
    </bindings>

to my WCF config. I am still pretty new to .netmf and gadgeteer, so I need to look up the raptors memory availability and all.

I was completely obsessing over this for DAYS, as soon as I post it on here, I have it within an hour…lol

Sorry to have wasted your time. I sincerely appreciating you taking a look.


#4

welcome to the best support “club” around. :slight_smile: We do hope you hang around !

And seriously, memory is usually not a problem on a raptor, its one of the beefier devices around :slight_smile:


#5

I was getting extremely frustrated because I am a professional .NET Developer. I should have been able to figure this out. I have also done quite a bit of hobby work on an Arduino.

Granted, I have not worked much with WCF or .NETMF, but I felt that I should not have taken three days to figure this out, lol. I was starting to obsess, and staying up WAY too late looking at it, which probably made it worse.

I see so much potential in these GHI boards, and I love being able to use .NET. I see alot of great information on these forums. I look forward to building more “stuff”. :smiley:

I think I am going to look out there and see if there are any open source projects out there that I can contribute to that involve Gadgeteer/.NETMF. I need another hobby to round it out to an even 1000…


#6

I have decided that working with WCF/DPWS on .NETMF is not for the faint of heart. I am making progress. Now I have been working on the implementation of a Server on the micro and connecting from a .Net Client.

It is very touchy! The files generated from the MFSvcUtil for Hosting the service are a bit different and missing some of the classes that the Examples had.

I can now communicate in both directions. Now to make it do something useful without breaking it too badly…


#7

WCF is one of the capabilities that doesn’t have many people leveraging it heavily so there’s not a lot of community assistance (sorry)