Ch4 code

17 views
Skip to first unread message

Ryan Wittibschlager

unread,
May 15, 2014, 9:48:27 PM5/15/14
to restinp...@googlegroups.com
I've been working at this for awhile now. Basically I can't get the code for Chapter 4 to work correctly.

Here is my code, it is pretty much the same as the code from the restinpractice website:


There are 3 solutions: Chapter4-DotNetOrderingClient, Chapter4-HttpListenerOrderingService, and Chapter4-WCFOrderingService

I can get the WCFOrderingService running in my browser, I can even to get request in my browser for order 1234.
Every time I run the DotNetOrderingClient solution, it gets a 400 Bad Request back, and I'm not sure what I'm doing wrong here.

I have not touched the HttpListenerOrderingService solution, I'll worry about it later (unless if it is needed for this demo).

If anyone has any advice or suggestions it would be greatly appreciated.

Thanks,
Ryan

Jim Webber

unread,
May 16, 2014, 10:22:39 AM5/16/14
to restinp...@googlegroups.com
Hi Ryan,

That's an empty repository. Can you push your code to it?

Jim
> --
> You received this message because you are subscribed to the Google Groups "restinpractice" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to restinpractic...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ryan Wittibschlager

unread,
Sep 5, 2014, 8:29:00 PM9/5/14
to restinp...@googlegroups.com
Hey Jim,

Sorry for the extremely delayed response! I became very busy over the past few months and had to put down my Rest In Practice book.

But I picked it back up this week. And I figured out my issue :) (also, sorry for the empty repo, I thought I pushed my code there but I guess I hadn't).

Ch. 4 .NET overview:

The .NET package comes with 3 solutions: a client (using System.Net to make web requests), and 2 different solutions that implement the "server" in different ways.

HttpListenerOrderingService also uses System.Net to listen for any incoming web requests. It's very dumb. It shaves off the last segment of the URI (presumably your orderID) and computes it's logic using the homemade OrderDatabase.

WCFOrderingService uses,well, WCF to host the service. So we're using the System.ServiceModel assemblies here to define service/operation contracts.

Firstly, in the Program.cs for your client you'll want to make the following 2 changes in order to make a valid request:
1. remove the "." character right after the 1 in "127.0.0.1.", that is technically an invalid URI.
2. you need to add the following line of code after creating your HttpWebRequest object:

      request.SendChunked = true

These are the changes I needed to make in order to get it working for me. Otherwise you'll continue to receive the error message I stated originally.

Secondly, you will need to decide on what solution you will use for your service. They designed the client so that it could use either service implementation, which kinda made it confusing for me without any documentation on it. :/

Try running WCFOrderingService (build, run without debugging). You should get a notification stating the VS dev server is running. Then, in your browser you can navigate to http://localhost:8080/OrderingService.svc/orders/1234 to verify the service is running (you will see an XML representation of the order). Then, if you run your client... boom! Nothing happens, but no exceptions should be thrown either. I debugged the WCF service by attaching it to the server and verified my client made the PUT request validly. It did... kinda. It's supposed to send an Order object (according to the operation contract) but we are only sending an XML-representation stream of the order. Anyway, the basics of the client PUT to server works, so I was happy.

Try running the HttpListener service. It will spawn a command prompt to notify you of what's going on. As you can see, nothing is defined if a PUT request is made (although they defined GET and DELETE??). So you should see your server spit out the web request method (i.e. PUT) as well as the orderID you send over (1234).

I'm guessing the authors of this code left A LOT out for us to implement ourselves? I'll be working on this code for a little while longer, because I want to get the PUT to work for both servers, then perhaps make the GET DELETE and POST methods to work. Feel free to email me with any questions on this chapter of code.

Thanks,
Ryan

Ryan Wittibschlager

unread,
Sep 6, 2014, 5:22:03 PM9/6/14
to restinp...@googlegroups.com
Wow, I didn't realize I was going back and forth with one of the authors of this book!

Thanks a lot Jim for spending some time helping me (and others) work through your book. I really appreciate it.

My last post was more or less intended for anyone who stumbles along the same problems I had when trying to run the .NET Ch. 4 code.

Regards,
Ryan
Reply all
Reply to author
Forward
0 new messages