passing Custom Class to Web Service
-
I posted on here recently about this but I am still none the wiser so again I come seekign advice. I have a web service and a website consuming this service. I would like to pass a custom class from the website to the webservice and vice versa. The trouble is every time it gives me a error message saying "type is not the same as loclahost.Type" How can I get them to agree that it the same type? I have built a VERY basic example of what I am trying to which can be found here: WS passing cutom class.zip If anyone can help at all then I would be very appreciative.
-
I posted on here recently about this but I am still none the wiser so again I come seekign advice. I have a web service and a website consuming this service. I would like to pass a custom class from the website to the webservice and vice versa. The trouble is every time it gives me a error message saying "type is not the same as loclahost.Type" How can I get them to agree that it the same type? I have built a VERY basic example of what I am trying to which can be found here: WS passing cutom class.zip If anyone can help at all then I would be very appreciative.
Define the type in the web service. Use that type, as defined in the web service, in your code, don't create a new class of the same name.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Define the type in the web service. Use that type, as defined in the web service, in your code, don't create a new class of the same name.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
There is a large amount of work with the custom class before and after the web service call which would make it very hard to use the type webservicename.type Also I am trying to create a web services approach with my current apparoach as a back up which would make it very hard to use webservicename.type.
-
There is a large amount of work with the custom class before and after the web service call which would make it very hard to use the type webservicename.type Also I am trying to create a web services approach with my current apparoach as a back up which would make it very hard to use webservicename.type.
From the error it seems you defined the class in your code TWICE. You can't do that. You simply have no choice but to define it once and use that class in both your webserver and client projects. As it stands now, both of your applications are saying that they have the proper definition of the class, even though they are exactly the same code, they're not the same class.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I posted on here recently about this but I am still none the wiser so again I come seekign advice. I have a web service and a website consuming this service. I would like to pass a custom class from the website to the webservice and vice versa. The trouble is every time it gives me a error message saying "type is not the same as loclahost.Type" How can I get them to agree that it the same type? I have built a VERY basic example of what I am trying to which can be found here: WS passing cutom class.zip If anyone can help at all then I would be very appreciative.
After a very quick look at your example I believe you need: Dim Person As New localhost.Simple Dim Proxy As localhost.Service Person = Proxy.Returnnames(Person) instead of Dim Person As New Eurofins.Simple Dim Proxy As localhost.Service Person = Proxy.Returnnames(Person) My thought on this being that a proxy class of type 'Simple' should have been created when you made a reference to the webservice. These generated proxy classes are marked up with alot of Soap attributes that make everything work. If you are referencing another class with the name of Simple instead of the generated proxy class I can understand why you would get errors because localhost.Service is expecting a class within it's namespace. You can actually navigate to the proxy class code through the object browser if you double click on the web reference. Also it is possible to do this without a web reference and create your own proxy class (or the gerated one and modify it) if that is what you want or need. Here's a sample from my code using xml serialization, actual classes not included. private UserInformation GetUserInfoFromWebService(Uri ServiceUri) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ServiceUri); request.Method="GET"; request.Credentials = CredentialCache.DefaultCredentials; request.ContentType="application/x-www-form-urlencoded"; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); XmlSerializer UserInfoSerializer= new XmlSerializer(typeof(UserInformation),"http://localhost/UserServices/"); Stream responseStream = response.GetResponseStream(); StreamReader responseReader = new StreamReader(responseStream); UserInformation UserInfo = (UserInformation)UserInfoSerializer.Deserialize(responseReader); responseStream.Close(); response.Close(); return UserInfo; } Hope this helps. -- modified at 11:12 Monday 21st May, 2007 -- modified at 11:14 Monday 21st May, 2007
topcoderjax