C# Web Service and Web Site sharing library, service returns different "type" of library object -


I have a web service and a web site (both C #) in the same solution (for now); I also have a class library in the solution, both web service and web site refer to this class library.

Web service has a webmooth that creates an object from the library and returns it back. The website tries to make it into a trainer object (again, from the same library)

  ProFitWebService.Service serviceConn = new ProFitWebService.Service (); ProFitLibrary.Trainer Authenticated TransLine = (ProFitLibrary.Trainer) serviceCon. GetAuthenticatedTrainer (_TrainerLogin.UserName);  

Although the following occurs as follows: "ProFitWebService.Trainer is not able to change the type of ProFitLibrary.Trainer"

Here is WebMethod:

< Pre> [WebMethod] Public ProFitLibrary.Trainer GetAuthenticatedTrainer (String Email) {ProFitLibrary.Trainer Return Instructor = New ProFitLibrary.Trainer (); SQL Command cmd = new SQL Command ( "SELECT * Trainers where Email Address = '' + email + '', con); conn.Open (); SqlDataReader reader, reader = CMD. Akskteyr Reader (); while (Reader. Read ()) {returnTrainer.TrainerId = reader.GetInt32 (reader.GetOrdinal ( "TrainerId")); return Trener. first name = Reedrkgetstring (reader.GetOrdinal ( "FirstName")); ReturnTrainer.ListName = reader.GetString (ReaderkGetOrdinal ( "LastName")); return Treneyr. phone number = Reedrkgetstring (Reedrkgetordinl ( "phone number")); return Trener. n = Reedrkgetstr Ing (Reedrkgetordinl ( "address")); ReturnTrainer.City = reader.GetString (reader.GetOrdinal ( "City")); ReturnTrainer.PostalCode = reader.GetString (reader.GetOrdinal ( "PostalCode")); ReturnTrainer. EmailAddress = reader.GetString (reader.GetOrdinal ( "EmailAddress"));} return return instructor;} update to: into profit Vebsewa trainer object on the web site. It was decided to issue:
  ProFitWebService.Service ServiceConn = New ProFitWebService.Service (); ProFitWebService.Trainer Authenticated Trayner = (ProFitWebService.Trainer) serviceCon. GetAuthenticatedTrainer (_TrainerLogin.UserName);  

I think the answer to this would be the service-based / prefixel type always returned from a web service - and I should not refer to the class library from both websites and the service - I Always make the webserver version of the object - Profit WebService Trainer etc.

When you are using libraries within a web service, can it be confirmed as a standard practice? Or if I'm making it more difficult then it really is!

Web service will give you the proxy class generated for you. These proxy classes look like classes from your library, but they are not of the same type.

If you want to treat objects coming back from your Shared Library from the Web Service, then you have some method to translate between library versions and proxy versions of these types. would be required.

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -