how can I test a WCF service using XAMPP to work with Apache server? - wcf

I built a WCF service on a windows virtual machine, and tested it with the WCF test client by typing this on my browser:
http://localhost/Service1.svc/getAllCustomers
... and it works pretty good. Now the problem is that I want to do the same test in my real computer (not the VM).
I'm using XAMPP on the VM, I have set the project on the htdocs folder, and I type this on my browser:
http://10.211.55.3/WCFWebService/Service1.svc.cs/getAllCustomers
The problem is that it doesn't return the result of calling getAllCustomers, instead it returns the Service1.svc.cs in plain text.
I want it to do the same thing it does on the VM - can someone tell me what the problem is? I think it's because on the VM it works with the WCF test client, and since my computer is a Mac I can't run the WCF test client.

A WCF service can't run on an Apache web server instead you should install IIS Server on the VM in order to test the service.
Refer to this: http://msdn.microsoft.com/en-us/library/ms733766.aspx

I found this with a Google query.
I kept the tab open, but continued exploring the other search results.
One I found particularly interesting was this one: WCF acting as Web Service without IIS
It appears WCF gives options other than IIS to host the web service (Console Application, Windows Application, Windows Services).
The Windows Service link is provided here: How to: Host a WCF Service in a Managed Windows Service
I have not done this, so I cannot elaborate on what problems you will run into.
I just want others that may run into this (like I did) to know that the one answer posted last year may not actually be the end of the road.

Related

Regarding wcf service hosting

i am new in wcf and started learning. i got one confusion like that i create a small wcf service and just do not host it in IIS,console apps or win service but from another apps i can add the service reference of svc file and found it is working. if wcf can work without hosting in any place like "IIS,console apps or win service " then why people would alway host wcf service in IIS,console apps or win service. can anyone tell me the reason.
people use IIS and windows services in general because they are simpler to setup and run more consistently. they can also be hosted more easily on servers where the services can be configured to start automatically, and as usually wcf is used as a server communication method it is usually this that you want to do.
hosting in console applications is generally easier to setup for simple examples for testing purposes, when you want to test your services locally.
Whilst hosting in applications as possible it's a less common scenario to use wcf to communicate between 2 applications on the same machine.
EDIT:
Your original question asked why people always talk about IIS, services etc. The point I was making was that usually wcf is used for web services, and is usually run on a server other than the local machine. Even though it can be used for inter process communication on the same machine this is not the most common use case. This is why you see a lot of examples using IIS and not too many hosting it in a Windows forms app.

wcf service on windows 2003 server - works as server but not as a consumer/client

It is a very simple wcf service. Since my original wcf service didn't work there I decided to create one test service. Basically I'm using the default method GetData(int).
I hosted this service on windows 2003 server. It works well when I consume it from a different machine. I use a windows forms test application to consume this service. When I run this forms app on the same ws2003 server and attempt to consume the service on the same server it throws the following error:
There was no endpoint listening at http://...
I created another wcf client using asp.net, also silverlight, nothing works.
Basically, it looks like it can't consume any wcf service.
I couldn't figure out what could be the issue.
Basically, the machine had McAfee antivirus installed and was blocking http communication to aspnet_wp.exe.
The full path is c:\windows\microsoft.net\framework\v4.0.30319\aspnet_wp.exe
Everything works fine after unblocking this specific exe.

Hosting of WCF and Windows Services

My head hurts so much I think I need a bottle of aspirin...
I've created a WCF service and, with help of others from this site and the department I work in, the WCF service is running as a service on my development machine. Tested it with a console app and it works.
But, it's not supposed to be on my development machine. It needs to be on a different server.
This is difficult because the server it is supposed to reside on DOES NOT have Visual Studio installed on it.
So I cannot run the VS 2008 Command Prompt with installutil to run the WCF service as a service on that server.
Broadly speaking, you've got three options, all of which are described on MSDN:
Host the service under IIS
Self-host the service in any managed .NET application
Host the WCF service under a Windows Service
Which one is right for you depends on what your service is for, how it'll be consumed, how scalable and secure you need the set-up to be, and a dozen other things besides. Without knowing a bit more about what your service does and how it'll be used in your organisation, it's difficult to make a recommendation.
IIS hosting is easy to set up and is the way to go if you want to leverage all of the industrial-strength hosting functionality that a full-blown web server offers.
Self-hosting is quick and easy - you can knock out a WCF-hosting console app in two minutes flat - but is the clunky solution. You of course have to run the host application as a particular Windows user. Perhaps not ideal?
Hosting under a Windows service is the middle ground. It gives you that always-available functionality without having to be logged in as a specific user, but doesn't offer the configurability and scalability of the IIS solution. It takes a bit more effort than belting out a quick console app, but not much.
The server that the windows service will reside on will have the .NET Framework. INSTALLUTIL is located in the Microsoft.NET\Framework(version number) folder in the Windows directory.
For example, C:\Windows\Microsoft.NET\Framework\v2.0.50727.
No need to write a console app to host your service now (unless you want to).
You can also host your WCF service under IIS, check this out: MSDN - How to: Host a WCF Service in IIS. It really is just a five minute job :)

WCF Service doesnt run on IIS!

I have a WCF service hosted at local IIS. I created a ASP.NET website that consumes this service hosted at IIS.
While running it from Visual Studio WebDev Server, everything works fine, but as soon as i run the same website [after hosting in IIS] from the browser, the website doesnt seem to be communicating with the Service!
The same setup when runs from Visual Studio WebDev Server, doesnt function from IIS!
Any know isues?
Please help!
Thanks
I bet it's the address - when using Add Service Reference it will hardcode "localhost" into your ClientConfig file on the client.
Check this and implement a way to change over to your real (IIS) address at deploy time.
(A way to check you have the right deploy-time address is to pull it up in a browser, try navigating to "http://yoururl.com/MyService.svc" you should get a page that will link to the WSDL, letting you make sure you have the right address.. this is the address your client should look for)
Couple of things to check:
do you have a SVC file? Where is it located?
do you connect to the correct service address? It would be:
http://YourServerName/YourVirtualDirectory/YourServiceFile.svc
This is the address that you get when hosting in IIS - you cannot override that in your web.config, no matter how hard you try.
are the configurations for binding etc. identical on server and client?
have you turned on HttpGetEnabled for the service metadata? Can you navigate to the WSDL address and get the WSDL back??
http://YourServerName/YourVirtualDirectory/YourServiceFile.svc?wsdl
It sounds like you are not resetting the Service reference when you move it to the webserver. What you need to do after you have completed testing is to move your Service to be hosted by IIS, so deploy it to the server. Then you will need to re-reference, or update your reference in our web app before you deploy it.
Typically when testing your service it will run in the dev server at http://localhost:someport/myservice.svc
When you deploy it to IIS it will run on http://myserver.com/PossibleVDIR/myservice.svc
Once you take care of this you should be fine.

How can I use net.tcp without IIS?

I have a web site and build a wcf service in it. I can run the code by calling it from a test page in the web site. The web site is ran by the vs2010 development server.
I do have IIS 7 but never use it.
Now I want to use the NetTcpBinding instead of BasicHttpBinding, everyone says it should be enabled in IIS, but how can this be done without using IIS and keeping everything in 1 project?
Thanks for any help
edit: A Windows service would be a solution, but that would mean adding a project to the solution, I really want to keep everything in 1 website, took me quite some time to get the service in the website in the first place.
This is about my own test version of the website, the production server is out of my reach. The service must be expanded by other developers later on it's bad if they have to run IIS just to test the service.
One way is to host the WCF service in a Windows Service - see How to: Host WCF in a Windows Service Using TCP for sample code.
Are you talking about how to develop without using IIS7 or how to put the service into a production environment without IIS7?
If it's the latter, then Stuart's answer is correct, but otherwise I would suggest that you start to develop using the web server that you will eventually be hosting the web site/service on.
Hosting in IIS7 has several advantages over hosting in a Windows Service such as fault tolerance and process isolation already built in.
Thanks for the replies guys, it looks like I have 3 options:
1. Host the service in a seperate project.
2. Host the website in IIS.
3. Use HTTPS, also secure.
PS: My development environment is very different from production :(
In development I have unit testing and in production there are old ASP pages, that I can't even acces, but sometimes must refer to...