To be very surprised in this world today, I found a service (WCF) working without an address, including no base address specified. I am an mid level expert in WCF, however, was finding it so strange to see this behavior where we have address="" and no base address mentioned in config and also no other config files. When I asked this question to my colleague who was part of this development, he do not know the reason or logic, he just could make it work but do not know the reason. Any pointers please? Its WEBHTTP Binding
If your service is hosted in IIS you don't need to specify a fully-qualified endpoint address. This is because the base address used for the service always has to be the same as the address of the .svc file
When hosted in IIS, endpoint addresses are always considered to be relative to the address of the .svc file that represents the service
More here: https://msdn.microsoft.com/en-us/library/aa751792%28v=vs.110%29.aspx
When your service is self-hosted you can also leave the address empty. In this case, your service address will be the machine IP (or localhost) and .svc fine name.
You can launch a service host without providing any base address by omitting the base addresses altogether
More here: https://www.safaribooksonline.com/library/view/programming-wcf-services/0596526997/ch01s05.html
Related
I tried and googled many times, but can't solve this problem. Please help me!
These are my pictures
When I try to browse the SVC file, it throws the error :
XML Parsing Error : no element found.
Please help me
Supplying a fully-qualified endpoint address (for example, http://localhost/MyService.svc) can lead to errors in the deployment of the service if the endpoint address does not point to the IIS-application that hosts the service exposing the endpoint. Using relative endpoint addresses for hosted services avoids these potential conflicts. You could refer Deploying an Internet Information Services-Hosted WCF Service.
So, to achieve your requirement, use relative address, and host it in IIS, then you could use current machine IP to view your service.
I am hosting a web application using wcf service. So whenever i add a new serviceReference This below code comes and sit in my web.config file which is obvious
<endpoint address="http://localhost:8426/WcfService1/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
Now my question is everytime when i add serviceReference endPoint address will be added. I want to make that endpoint address Static. Store somewhere in the web.Config.
The idea behind the change is when i am going to host oon different server there might be more than 100 serviceReference. So each time i cant change 100 endpoint address. So how to make it static and access it.
After you host your WCF service on ISS, it will be hosted on a static addess. Something like "www.example.com/WcfService1/Service1.svc". Now the web application where you want to consume this service, where you have the service reference will have web.config with client end point address. You have to manually replace this. If you are concerned about updating this in multiple services, look into Build Deployment Configurations. Build deployment techniques have options to replace these configuration values in config files based on environment where you are deployein the buiuld.
http://www.asp.net/web-forms/overview/deployment/configuring-team-foundation-server-for-web-deployment/creating-a-build-definition-that-supports-deployment
When service references once generated for localhost you do not need regenerate them after deployment. You just need to change endpoint addressers in your web.config files. For services they can be still localhost, but for service consumers (mean client section in web.config) they should contain real reachable host name.
If all your wcf services are public and supposed to be visible from the outside, they will be available with host names, according to your deployment configuration. And you should follow the suggestion of Shetty.
But you can use different build/deployment systems, where some kind of templates for config files can be used, and host names would be replaced with real host names during deployment.
If all your services are supposed to be used only by web application, which is public, and all the services should not be available from the outside, it can make sense to use custom DNS names for services like sales.servise.company.int products.service.company.int and hardcode them in web.config files.
During development you simply specify those host names in your local /etc/hosts file, and in production release you can do same (tweak hosts file on web application machine) or/and bind this DNS definition in your private DNS server and load balancer
Suppose I've one WCF service hosted in a Windows service running on a machine on LAN. I want to make this service to be consumed by applications running on other machines on same LAN. Further assume I've hosted WCF service in a Windows service using TCP. So the app config file will have the base address mentioned something like this:
<add baseAddress="net.tcp://localhost:8523/Service1" />
My question is will this service be accessed by clients over LAN though I've mentioned localhost? What is the right way to mention base address so that service could be consumed by clients on LAN? Is any arbitrary address is valid? If localhost is valid, which port shall I mention?
you need to specify the actual ip. i think localhost is just for the current machine. localhost is an alias for the default address 127.0.0.1
Is there a way to host a wcf service:
without extension
with relative endpoint addresses (the server address should be known automatically)
without metadata (the contract is available for the client)
basicHttp binding
If something is not achievable i will accept that. Already tried a approach but got
no metadata -> Other Question.
If you're hosting a WCF (SOAP) service in IIS, you need a service.svc file (or at least an endpoint with the .svc extension using file-less service activation in .NET 4) so that IIS understands that this is a WCF SOAP endpoint and routes requests accordingly. In IIS, the virtual directory where your service lives basically determines your service endpoint's address, therefore you can use relative addresses (relative to the virtual directory) to define your service's endpoint address.
If you self-host your WCF service in a managed application (Windows NT Service, or just a plain .NET console app), then you don't need a .svc file - your managed app handles the requests - but at the same time, since there is no "hosting infrastructure" in place, you need to define a **fully qualified" endpoint address - you cannot just use a relative address (relative to what??)
So you can either have relative addresses (in IIS, but with a .svc file), or you can have no extension (with self-hosting, but then you must supply a fully qualified service endpoint address). You cannot have both at the same time.
Whether or not your service endpoint has and exposes metadata is just a question of adding (or not adding) the ServiceMetaData service behavior to your service definition.
I've got a WCF service running on a LAN IIS which is accessible from the internet as well.
The client that consumes the service is an application that runs on the LAN and remotely through the internet. There is no forwarding of anything on the DNS server redirecting http://www.corporate.com/Service to http://serverName/Service so I'm figuring I'll need 2 endpoints on the client.
How do you setup multiple endpoints in the client (is it as simple as copying the existing enpoint generated in the app.config but changing the address?) and how do you configure the client to use a particular endpoint?
You may store endpoint addresses either at app.config, or at resource strings. Then using any condition you pass needed endpoint address to service constructor.
var endpoint = ApplicationSettings.IsRemote ? Resources.RemoteEndPoint: Resources.LocalEndPoint;
var service = new MyWCFService(new BasicHttpBinding(), new Endpoint(endpoint));
The app.config (or web.config) for each copy of the application should have the endpoint for the service set based on the one it needs. For LAN installations, use the LAN-visible endpoint; for all others, use the Internet one.
It may save you a trip to the router, but why not just use the internet endpoint everywhere? If your LAN computers have a gateway to the Net, they can see the externally-visible address.
It is as simple as changing the address and using the endpoint generated in the app config. You may have to change security modes depending on what is supported on either server, or whether they are both running HTTPS or not. We have an application where we build the target endpoint based on relative path to the current URL in a Silverlight application. We also dynamically change the security mode based on HTTPS being present and it works great.