Web Services

Solarion

Honorary Master
Joined
Nov 14, 2012
Messages
28,050
Reaction score
17,804
Have tried all I know to try. It simply won't let me add a reference to a webservice. This should be like the easiest thing in the book and it's not working. What have I done wrong?

FYI I've googled the pants off of this, to no avail. Nobody knows.

Screenshot-2.jpg
 
It thinks studentwebservice is a namespace. You are using it as a type. Try studentwebservice(dot) And then intellisense. Maybe the reference has that namespace and i tellisense will show you the types in that namespace. Usually if u have a typename same as part of a namespace it get confused.
 
It thinks studentwebservice is a namespace. You are using it as a type. Try studentwebservice(dot) And then intellisense. Maybe the reference has that namespace and i tellisense will show you the types in that namespace. Usually if u have a typename same as part of a namespace it get confused.

That worked thanks. I'll have to go back to basics on creating web services, getting some funky metadata errors and when it gets to the point of stackoverflow telling you to start to hacking apart the Web.Config file you know something has gone horribly wrong.

Edit: I get some good looking XML and JSON from what I made, but the moment I want to consume it in an application, the wheels start falling off.

Screenshot-3.jpg
 
I assume you consume it bby using the proxy class generated by the web ref?
 
Nooo I'm staying the hell away from SOAP! :oops:

It's WCF. This is the endpoint.
Ah right. Never used wcf tho. I use http get/post low level with json. Its more manual but i prefer the control i have over everything. Did you do the backend also.?
 
Ah right. Never used wcf tho. I use http get/post low level with json. Its more manual but i prefer the control i have over everything. Did you do the backend also.?

Yeah the back end is fairly simple at the moment. Has CRUD for SQL and this is the api front end for it.

Screenshot-5.jpg


Ah right. Never used wcf tho. I use http get/post low level with json.

If it comes to it I'll go that route. Mostly feeling my way around :p
 
Found the problem. No endpoint has been configured. You find this out by right clicking on Web.config and this configuration dialog appears.

Screenshot-6.jpg
 
SO what do I do with the XML from the service? It's pretty useless to me at the moment. How do I use it?

I did the whole xsd utility/http://xmltocsharp.azurewebsites.net/ route. Gave me this gibberish class. No idea what to do with it.
 
If you are using the generated web service client, then you don’t need to do anything with the xml response, as the wrappers/dtos have already been created.

Client.GetStudents should return a List<Student>

Out of interest sake, why does your screenshot show List<Students>? i.e. plural instead of singular “Student”?



Honestly find it far simpler to just use WebApi and create ApiControllers for publishing, and manually using something like RestSharp for consuming, and if I must consume Xml, then manually create DTO’s with [XmlElement, XmlAttribute, etc] attributes
 
To that affect, albeit that is a pretty poor example. Not restful, no separation of concerns.

Eg /customers/deleteCustomerById/124 instead of DELETE /customers/124

I would ditch wizards completely in Visual studio. What they are good for is creating a new product in a solution, that has the boiler plate setup. I would never use them to create a controller, because for me it is just quicker to rightclick -> new class and manually add the “: ApiContoller” ie inheritence.
Doing it manually also just makes it explicitly clear what the outcome will be.
 
Yep like kabal said the web ref creates the proxy objs for you. Personally i prefer json and use newtonsoft for serialization and deserialization. Look carefully at what kabal posted. Very good advice. What you are trying to do is not complex and should not have to take long or be difficult at all.
 
To that affect, albeit that is a pretty poor example. Not restful, no separation of concerns.

Eg /customers/deleteCustomerById/124 instead of DELETE /customers/124

I would ditch wizards completely in Visual studio. What they are good for is creating a new product in a solution, that has the boiler plate setup. I would never use them to create a controller, because for me it is just quicker to rightclick -> new class and manually add the “: ApiContoller” ie inheritence.
Doing it manually also just makes it explicitly clear what the outcome will be.
Yep like kabal said the web ref creates the proxy objs for you. Personally i prefer json and use newtonsoft for serialization and deserialization. Look carefully at what kabal posted. Very good advice. What you are trying to do is not complex and should not have to take long or be difficult at all.

Thank-you both guys, feels like I'm put on the right track with this now. Been battling with this because there is so much legacy stuff lying around. @_kabal_ I did notice the lack of separation, I will sort that one out. The data layer for example with be on it's own and the service/data will reside on the hosting (I will find myself a host at some point to do this properly) for now I will just run it as a separate service locally.

I'll start to put something together this week.
 
You can try free azure to mock a webapi. Look at azure functions consumption plan. Or i think mock.io you can mock webapis as well. The webapi controller excl data access should be about 3lines of code max. Then client side pretty much the same. When i am in charge of the client as well as webapi, i always create an assembly that only contains the DTOs. Then in the webapi i reference the assembly , create the dto and return it from the controller method. Then on the client i also reference the dto assembly and use the dto as the type to deserialise the json into the dto. Literally single digit number of lines of code
 
Top
Sign up to the MyBroadband newsletter
X