# .NET and More > WPF, WCF, WF >  Internet Service

## Pac_741

Hello, i'm developing a contact manager called "contacts", i got an idea which i would like to add to the program, i would like users to be able to share  contacts through the internet, for example "A" person has one contact that "B" person would like to have it, the problem is i have no idea on how to do it, how to share data through pcs through the internet, so if someone can give me a hand with this one, i'll really appreciate it.

Thanks  :Smilie:

----------


## mendhak

If you want users to be able to share the contacts then you'll need some sort of an online 'repository' to hold this information so that it can be retrieved.  It's probable that a user won't constantly keep sharing this information so you can keep managing all the contacts on the local computer, but when the user chooses to share, 'export' it in an XML format to a web service.  The web service can store it in a manner that attributes it to person B so that person B can get his application to query the web service, get the information out and 'add' it to their local repository.

----------


## Pac_741

Ok, thanks for the answer, the contacts of the user will be located in his or her computer, what i need to know is how can i create that type of internet service, to share the xml file the contacts are being exported, or to create a peer to peer connection, i was searching at the C4F vista peer to peer toolkit but without results.
Does anyone knows more about this ? thank you

----------


## DeanMc

This is rather over simplified but you would need to have a server (or rent some space, like you do for a website) On this server you would have an application (which is sometimes confusingly called a server too). This application would accept requests from user A and send them to user B. The reason for the XML is it can be serialised easily and yet still retain the structural integrity of the data.

----------


## Pac_741

Ok, thanks for your answer

----------


## Pac_741

I was thinking and maybe the file the user wants to share, if he or she has a live id, maybe the file can be uploaded to the skydrive of that user, and then when the user is using other computer with the program i did, he or she just gives his or her live id, and then the file containing certain values is found and load the contacts from there, but has anyone tried to upload files to skydrive using C#.

thanks

----------


## Hamish

What??? A web server??? Rent room??? Isn't this the WCF forum?  :Stick Out Tongue: 
Couldn't you just build a WCF service into your application that exposes a method to add a contact to your address book? The 'client' (the one wanting to send the contact) could just call it and pass it a contact object.

[edit]
This has 2 assumptions: (A) You have a class for your contacts.... (B) Both users are online at the time.
[/edit]

----------


## chris128

I would agree with Hamish on this one (and I think both of those assumptions are fair ones). Why bother uploading the contacts to one location just for the other user to download them, just send them straight from one user to the other.

----------


## Pac_741

Thanks for your answers, i've been reading a little bit about WCF, but what i've read doesn't say i can use WCF to share data, or a file, etc.. between User A and User B, if i'm wrong please correct me, does WCF use peer to peer ?? thanks

----------


## chris128

From what I understand WCF can 'share' whatever you want it to share... in your case it would be a class that holds the data for the contact (e.g a class that contains the name, phone number etc of the contact).

Have a look at this to get an idea of how you actually create a WCF service: http://channel9.msdn.com/shows/Endpo...t-WCF-Service/

----------


## Pac_741

What if what i want to share is a generic list, containing the data for the contact, would that be possible ?

----------


## Pac_741

Thank you very much chris128, that video made me get started on how to do it. thanks

----------


## chris128

> What if what i want to share is a generic list, containing the data for the contact, would that be possible ?


Yeah I think that should be no problem at all

----------


## mendhak

I disagree with Chris and Hamish - those are quick and dirty solutions with no regards to scalability or performance.  A WCF service sitting on the Internet does not constrain you to having both both machines on at the same time _and_ you're going to have trouble performing netTcp over the Internet, ISPs won't be happy with that.  Having the contacts in a single place also allows reinstalls or usage on more computers, by the same user, so that the contacts are in sync.

----------


## DeanMc

I agree.

----------


## chris128

What do you mean by "trouble performing netTcp over the Internet" :S
TCP/IP is THE standard internet protocol (which you know of course) so I'm a little confused.

Anyway, when you send a file to someone over Microsoft's MSN Messenger, you dont send the file through the MSN services (unless the newer versions of MSN do things differently), MSn establishes a connection directly between you and the recipient. So I dont see how this is a "quick dirty" solution if it is good enough for one of the most popular IM apps out there.

----------


## Hamish

Chris, netTcp may not necessarily be 100% equal to TCP/IP (there is no mention of IP in the name, and if it's just TCP it's non-routable), so I don't know, it may be a problem. I wonder why you wouldn't just use wsHttps though... HTTPS is available almost anywhere....

And I personally think that exchanging contact information should be something that's done while both users are online and can give confirmation. I would not want to expose my contact list on a web service. I may be paranoid, but when they're out to get you, that makes perfect sense.  :Smilie:

----------


## chris128

Ah it seems you are right, I just assumed it was TCP/IP as I have never actually heard the TCP protocol being used with anything other than IP, but I guess I should not have assumed!



> Windows Communication Foundation (WCF) provides a new TCP-based network protocol (net.tcp://) for high-performance communication

----------


## mendhak

Hey, assumptions are alright, I make those about WPF all the time.  (See other thread)

----------


## Pac_741

So, guys i really don't know much about internet services, sockets, and all the stuff you are talking about, so i'm pretty lost.

Thank you anyways for your answers.

----------


## Hamish

I guess our combined answer to you is another question:
What do you want your application to do? Should it be able to exchange contact information when the sending party is offline? If so, you need a web server to run a WCF service that offers the contents of the address book. If not, you can use the application itself to run that same service.

----------


## Pac_741

Ok, what i want to do, is really simple, but i don't know how to do it, what i want my application to do, is let's say User A wants a contact, he or she wants to share, with User B, and both have an internet connection, and then User A, sends that contact to user B, then User B gets a message Displaying User A wants to share this contact with you, so User B can add that contact, i want to do no more and no less than that, i don't want contacts to be stored in a service, i want nothing of that, the contacts are being saved in the application startup path, give that explanation of what i want to do, will i still have to use WCF services? is that the only way to do it, is it the easiest way ?

Thank you all of your answers.  :Smilie:

----------


## Hamish

OK. Clear...
First of all, WCF is *not* the only way to send information from one program to another, this is however the WPF, WCF and WF forum, so it's logical you're going to get a WCF answer here.  :Smilie: 
Second, if you are going to use WCF, you are *always* going to use a service. The question we discussed was if you wanted to build this service into your application, or use an seperate web server to host it. From what you described, you want to build it into your application.

I am quite new to WCF myself (it's new, so most people are), so I can't give you a full explanation on how to do it, but I have watched the first couple of videos from this list, and I think with some time (and help from this forum) I could do it. So I think you can too.....

----------


## mendhak

Several ways to do it.  

One way is to use TcpClient to connect straight to the other user and send the information across.  This would be what chris described.

The other way is to get yourself a web host, create a WCF service on it and have each application poll the service at regular intervals for updates.

And on and on and on.

----------


## chris128

Isnt there another way - having each client app host its own WCF service that is capable of sending/receiving the information? So basically exactly the same as the TCPClient method you mentioned but just using WCF instead because from my experience (which isnt a lot) its not easy to send anything other than plain text strings via TcpClient.

----------


## Hamish

Yes, that's what I mean by building the service into your application. This video shows you how to do it. Apparently it is called self-hosting.

----------

