hi,
Can someone plz show me steps to create a simple wcf,,,I searched a lot and understood the concept but i am totally confused looking at different ways to create a wcf and am not able to land on developing a simple wcf....plz could some one show me clearly...how can it be done...waiting 4 reply..
thanks
Mumtaz
Loading
Mumtaz SuraniPosted Aug 6, 2009, 1:06 AM
I think i was very confused n took some tym to analyze n try out the code given by u....ok..i tried out the code given by u...ill jst write in steps what i did so that i can receive solution to my problem..
*I made a new wcfservicelibrary ,which has service.cs n Iservice.cs
*I then wrote the code given by u in the Iservice and service ,which has interface and its implementation..written..
*then i added a c# class library...which has a class as client.cs...in which i have written the client code given by u..
*I added reference to that client ...(wcfservicelibrary)..
* Build succeded..
*but when i run it....or debug it...
*there is an error stating.."The client was unable to retrive service metadata.Make sure that the service is running and exposing metadata"..
*there is also a service host window that pops and has 3 columns named service,status and metadata address....
*service shows myservicename.server.serviceimplementation,,status is stopped...and there is nothing in the metadata address column...
*I have given u a very detailed expalnation....so that u understand the exact problem..
*thanks 4 ur reply .....waiting 4 this reply as soon as possible..
Roei BarPosted Aug 3, 2009, 8:23 AM
the WCF project type, cannot be used out of IIS, unless you use IIS 7. its based on the idea that your WCF Host is Basically the IIS Server, meaning that your Only Binding in IIS 6 is HTTP and nothing else
Mumtaz SuraniPosted Aug 3, 2009, 8:05 AM
Actually iam new to wcf...and just want to create a very small n simple wcf possible so that i get an idea of how it is done practically(client server communication)..see from your reply i got some views from it....but then actually i dnt knw how is it created ....I mean....to begin,u click wcf servicelibrary or class or wcfserviceapplication or consoleapplication.....this all confused me as all these different options were used on different sites that made me confuse more...landing in confusion...
I also knw what for contract is used,some basics from articles on net....but i would want a simple standard way that would show me clearly how wcf operates....once i understand the flow...ill implement that with my windows service that i have created....difficult terms r problematic me as iam already confused.....so could u give me a clear idea of developing a wcf.....very clear specification...waiting 4 the reply.....n thanks
Roei BarPosted Aug 3, 2009, 7:47 AM
using System; using System.Collections.Generic; using System.Text; using System.ServiceModel; namespace WCFSimple.Contract { [ServiceContract] public interface IService { [OperationContract] string Ping(string name); } } namespace WCFSimple.Server { [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] class ServiceImplementation : WCFSimple.Contract.IService { #region IService Members public string Ping(string name) { Console.WriteLine("SERVER - Processing Ping('{0}')", name); return "Hello, " + name; } #endregion } public class Program { private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false); public static void Main() { ServiceHost svh = new ServiceHost(typeof(ServiceImplementation)); svh.AddServiceEndpoint( typeof(WCFSimple.Contract.IService), new NetTcpBinding(), "net.tcp://localhost:8000"); svh.Open(); Console.WriteLine("SERVER - Running..."); stopFlag.WaitOne(); Console.WriteLine("SERVER - Shutting down..."); svh.Close(); Console.WriteLine("SERVER - Shut down!"); } public static void Stop() { stopFlag.Set(); } } }// This is the Client namespace WCFSimple { class Program { static void Main(string[] args) { Console.WriteLine("WCF Simple Demo"); // start server System.Threading.Thread thServer = new System.Threading.Thread(WCFSimple.Server.Program.Main); thServer.IsBackground = true; thServer.Start(); System.Threading.Thread.Sleep(1000); // wait for server to start up // run client ChannelFactory scf;
scf = new ChannelFactory(
new NetTcpBinding(),
"net.tcp://localhost:8000");
WCFSimple.Contract.IService s;
s = scf.CreateChannel();
while (true)
{
Console.Write("CLIENT - Name: ");
string name = Console.ReadLine();
if (name == "") break;
string response = s.Ping(name);
Console.WriteLine("CLIENT - Response from service: " + response);
}
(s as ICommunicationObject).Close();
// shutdown server
WCFSimple.Server.Program.Stop();
thServer.Join();
}
}
}
Roei BarPosted Aug 3, 2009, 7:26 AM
i can understand yuour fustration, this is hell on earth to try and figure this out, let me try to shade some light into this.
wcf is basically a binding issue nothing more, you have a server which is hosting DataContract, the datacontract enable you to perform access and recieve data from the server, DataContracts have many options, like one way which is actualy like (void), security wheter its on Message Level or Transport Level.
once we build the datacontract all we need is to build either :
1. console app
2. Windows Service
3. IIS Site
that will be the Host for our service, this is the container to recieve the connections to.
on the other end we have a client, the client needs to have a conection to the url that the Server is Exposing, and then we can either create a ServiceChannel that is practicaly an Interface proxy to execute the Method invoke,
or create a Client Command, by "Add Service Referance" just like in Web Service.
if you want a simple example, just say the word... good luck mate.