Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,
I have created a WCF Restfull service.

My Operation Contract is
[OperationContract]
       [WebGet(UriTemplate = "Patient/{id}")]
       Patient GetPatient(string id);



public Patient GetPatient(string id)
       {
           try
           {
               int patientId = Convert.ToInt32(id);

               using (var db = new PatientInformationEntities())
               {
                   return db.Patients.SingleOrDefault(p => p.Id == patientId);
               }
           }
           catch (Exception ex)
           {
               throw new FaultException(ex.Message);
           }
       }



I have hosted this Service on a console Application. Now when i am trying to consume it I am facing problem that this Resource returns an object of type Patient . And as i don't have any proxy available on client a can't consume the response. I am New to WCF and REST. I know this is a silly question but still do i need to create a Patient class at client too ?? If yes whats the purpose of the service if i am asking client to create a class (There may be many classes that needs to be generated in a production environment.) If no howdo i consume this object ?

WebClient Client = new WebClient();
           string path = "http://localhost:8080/PatientService/";
           string Result = null;

           switch (OpCode)
           {
               case 1 :
                   Console.WriteLine("Enter Patient Id");
                   string id = Console.ReadLine();
                   string GetPatient =path + "Patient/" + id;
                   byte[] abc = Client.DownloadData((new Uri( GetPatient)));
                   Stream stream = new MemoryStream(abc);
                   DataContractSerializer obj = new DataContractSerializer(typeof(String));
                    var X =  obj.ReadObject(stream).ToString();
                   Console.WriteLine();
                   Console.WriteLine();
                   Console.ReadLine();
                   break;


           }


Here in the Serializer the type should be of Type Patient. but it is not available to the client as there is no proxy. Any sort of help is much appreciated. Thanks
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900