Consuming WCF Service

Good Afternoon, I´m working with G120 Module and NETMF V4.3. I need to consume a WCF service and I hoped It was as simple as in .NET framework, I mean, something like this:

Service1Client client = new Service1Client();
client.Open();
// Use client methods.
client.Close();

But I discovered that .NETMF doesn´t have the “Add Reference → Service reference” option, so I tried to make a .NET framework dll and use it on .NETMF but it turns out that generic dll´s cannot be compiled. Therefore, I decided to see the samples (HelloWorldClient_WCF and HelloWorldServer_WCF) as well as the forums. I found two different approaches:

https://www.ghielectronics.com/community/codeshare/entry/814

https://www.ghielectronics.com/community/forum/search?page=2&q=SOAP&field=date&order=desc&group=1

It is stated in the first option that the code will work with both V4.2 and V4.3 but I dont have:
System.Collections.Generic
System.Linq
System.ServiceModel.Discovery
System.Collections.ObjectModel
System.ServiceModel

So I´m working with the second option. Does anyone have experience dealing with consuming web services? can anyone give me some advices regarding how can I consume a regular web service in NETMF V4.3?

BR.

In the code share mentioned above,
The server is for you netmf board, the client is for your pc… not the other way around…

@ Jay Jay Thanks for your clarification, Do you have any idea how can I do what I´m looking for, use my G120 module app to consume a web service? I´m searching but I´m stuck.

@ Miguel - As Jay Jay mentioned, the Codeshare you linked is setup so your Micro Framework device acts as the WCF server and your PC acts as the WCF client. If you want to reverse those roles, you will need to rewrite the WCF client code slightly because NETMF does not have the namespaces you mentioned nor does it support generics.

The samples you also mentioned should be useful in getting started with WCF.

1 Like

@ John, Thanks, during this week I will rewrite the code and make some tests. I would let you know the outcome. Thank you for your response.

Good afternoon, I already consume the “HelloWorldServer_MF” server in my application and works fine. The second step is to consume my client´s web service instead of the default example mentioned above. I have a simple question in order to know what is going wrong. The documetation says that if the server app uses “wsHttpBinding” you should use protocolVersion11. I saw my client´s web service and uses basicHttpBinding, and I guess this is why it isn´t working. FYI, my discover function is always returning false with basicHttpBinding service, while works perfectly with the “HelloWorldServer_MF” example.

Do you think this binding differences could cause this discover problems?

Thank you very much for your information and cooperation.

yes, it’s all about the binding :whistle:

Have you included an endpoint which uses the ws2007HttpBinding ?

.......

Hi guys, I`ve struggled a lot trying to consume an existing web service hosted in WCF on a Windows Service / IIS, and maybe that´s not possible. The example works because the HelloWorldServer_WCF is running on my PC, but I haven´t seen any examples of NETMF devices connecting to IIS hosted services. Is it possible to do this?

Thanks for your replies and cooperation.

@ Miguel - It is definitely possible as I have had a Cerb 40 II talking to a Web API (vs WCF) based REST service hosted in a Azure instance of IIS. It was part of a garage door opener project I used to become familiar with NETMF development. It is no longer in use, but it worked at one time.

In a WCF Service, if you adorn you service method studs with the WebInvoke attribute then you can reach your WCF service using simple HTTP calls.


           [WebInvoke(UriTemplate = "/device/get/{guid}", Method = "POST", ResponseFormat  = WebMessageFormat.Json | WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Json | WebMessageFormat.Xml)]	
    	[OperationContract]		
    	Device GetDevice(string guid);

To call your WCF service “traditionally”, you need to use the C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFSvcUtil.exe tool to generate the client code used to call your service from within a NETMF device.

So search the web for how to use MFSvcUtil.exe. It is fairly simple. Just open a console window and run the exe against your WCF service (C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFSvcUtil.exe http://you-site.com/YourService.svc?wsdl /v)
Add the generated files to your NETMF project and call your service.
Also, be sure to include the ws2007HttpBinding service endpoint binding I describe a few posts ago. :dance:

To answer your question, I don’t think you can eat a wcf service

(get it? Consume?) :whistle:

of course you can eat WCF :whistle:

http://www.allaboutchocolate.co.nz/shop/wcf-chilli-lime-nuts/

2 Likes

Thanks for your replies. I decided to use a socket connection and send all the SOAP protocol. It´s working perfectly, and since I´m in a rush, I will stick with this solution until I have some more spare time to deal with this situation.

@ Miguel - Hi Miguel. I have your same problem and I saw that you solved it using socket connection and the SOAP protocol. Can I ask you how precisely did you do it?

Thanks a lot.