|
title: Put the knife down and take a green herb, dude. |
descrip: One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com Using 89% of the same design the blog had in 2001. |
|||||||||
|
FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white. As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green. |
||||||||||
|
x
MarkUpDown is the best Markdown editor for professionals on Windows 10. It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support. Features you won't find anywhere else include...
You've wasted more than $15 of your time looking for a great Markdown editor. Stop looking. MarkUpDown is the app you're looking for. Learn more or head over to the 'Store now! |
||||||||||
| Tuesday, June 17, 2025 | ||||||||||
|
Okay, was looking back through WCF earlier this week for a prospective client, and figured I'd leave some notes. Here's the stock code, give or take:
And all that's in Again, this is the stock WCF project so far. Not overly fancy. I wanted to be able to hit the stock endpoint from a WCF project in Visual Studio without using a WCF client. Getting to the WSDL file was easy: You can steal that from the page the WCF Test Client refers to if nothing else. For me, that stock page was:
Here's some of the startup page's contents:
Then the WSDL itself:
What you want to be able to do to invoke a service endpoint directly is, of course, find its URL. In my case, with a little help from SoapUI, I figured out it was the same URL that started up initially:
The first key is that you have to set up two headers to the request:
But you seem to have to send it a body in a POST -- GET gives you that stock opening page again. (Since GET and POST are REST conventions, I half-way expected the WCF service not to care, especially since we know GET can have a body now.) I am not yet going to claim I know how the WSDL tells you what your input parameters should have looked like.
Again, do this all in a Postman POST request with a body that's raw with XML as its type and you're golden. Change
I do not miss XML. Update: Ha! Wish I'd talked to myself from 13 years ago first! Labels: c#, noteToSelf, wcf posted by Jalindrine at 6/17/2025 07:27:00 PM |
||||||||||
| Thursday, May 03, 2012 | ||||||||||
|
The most annoying thing about setting up a WCF is the number of things that seem to work in the local testing server that'll explode in IIS. The local testing server that you can invoke with F5 is very lenient. But before we get into the complicated stuff, a quick list of System-Provided Bindings from Microsoft:
Fair warning: I've done this three or four times now to make sure things work, but I haven't started from scratch on a new machine to run through the steps as I present them, here. Could be wonky somewhere. YMMV. So let's start a WCF Service project. You select File >>> New Web Site >>>WCF Service. Save the new project in IIS's root folder. That'll create a project with the file structure seen below: ![]() Looking in Web.config, you'll see that, by default, this project has two endpoints. One is the MEX endpoint, which is nice, but not really the business end of things. The other is a wsHttpBinding. That's important, because, as we learned above, that expects to be called from a SOAP-compliant client. If you try hitting F5 off the bat, it'll seemingly work, first going to a URL like this one: http://localhost:50319/WCFService1/Service.svc But if you try to view the GetData method, which is one of the two IService methods that Service.cs implemented by default, using a URL like this one: http://localhost:50319/WCFService1/Service.svc/GetData ... you get no response, just a 400 error. So it's worth saying that it's odd to have a SOAP client in my line of programming. You'd usually rather send out a very simple AJAX request to a URL from a web page to the WCF and receive some JSON back to parse in Javascript. The take-home is that we need to remove the wsHttpBinding (set up for SOAP) and set up webHttpBinding (ready for REST) instead. The endpoints that Visual Studio inserts into web.config by default are below: <endpoint address="" Our next step is to change that wsHttpBinding endpoint to one with webHttpBinding. I've also inserted the additional overhead of adding a JsonBehavior. Honestly, not sure what that's doing yet, but I think I want it. <system.serviceModel>(In case I've screwed up, the entire config is here.) Again, switching from wsHttpBinding to webHttpBinding makes it so that we can use a URL to access the method. With wsHttpBinding, you'd have to have a SOAP client, which involves insane amounts of overhead for most of my applications. There's more required than that, however. If you've got the same standard setup as I get in VS 2010, you've got two methods in the Service.cs file. One is pretty easy to set up to listen to query strings for its parameters; [OperationContract]Now, you should be able to nav to GetData and slap in a param of "?value=1231" and have that number repeat back to you with a URL like this: http://localhost:50319/WCFService1/Service.svc/GetData?value=10 You'll see "You entered: 10" (with quotes) in the web page. ![]() You can also leave the port off if you followed the instructions and created the dir in IIS' home dir and created the application using Internet Information Server (IIS) Manager. Go to your default web site, find your server's folder, right click, convert to application, and voila: ![]() Unfortunately, the other method in the default project (GetDataUsingDataContract) is more complicated, as if you try to turn it into a GET-able method, your WCF Service will complain about the CompositeType hand-rolled datatype that's also part of the project VS 2010 dreams up for you. [OperationContract] You can't webget that because CompositeType isn't serializable. Operation 'GetDataUsingDataContract' in contract 'IService' has a query variable named 'composite' of type 'CompositeType', but type 'CompositeType' is not convertible by 'QueryStringConverter'. Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'. Whoops. I'm not going to go into serializing to JSON right now. All things considered, that's an easy afterthought after this XML config wading. So perhaps not the best composed, but that's today's lesson. (A decent walkthrough of a slightly different way to go about this here.) posted by ruffin at 5/03/2012 03:52:00 PM |
||||||||||
|
Creating a WCF service that consumes an ASMX service: I am looking for guidelines on which "project type" to use in getting started via Visual Studio 2008 and C#. Here the specific need is having my WCF service call an ASMX service. Labels: wcf posted by ruffin at 5/03/2012 11:28:00 AM |
||||||||||
|
| ||||||||||
|
|
All posts can be accessed here: Just the last year o' posts: |
|||||||||||||||||||||
|
||||||||||||||||||||||
|
|
|
|