How to make endpoint address static while using wcf - c#

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

Related

Does WCF Works without an address including baseaddress?

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

Error while consuming wcf service

I created a wcf application library with no modification from the original example and I hosted it in IIS. It's on a remote computer and using chrome i can see that the service is up and running but if i try to create a config file using
svcutil.exe http://IP_HERE/serv/WcfServiceLibrary1.Service1.svc?wsdl
i receive the following error.
I think that it has something to do with the application pool. What do you think?
My default config: http://pastebin.com/a355LcWp
After checking your service config file I found that you are hosting service on port 8733 which is mentioned in base address value. You need to make sure that you include this port number while accessing wsdl.

WCF Host service without extension with metadata to consume on clientside with known contract

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.

how to access webservice deployed in remote server

Please help me , how to add web service which is deployed in remote server. externally i unable to access that service..in that remote server only that service will run but we don't have Ms.net Environment to add service to my application in that server.
So please guide me how to add that web service to my application ,not accessig externally that service URl, internally Executing that URl.
How can i add that service to my application on my developer PC ?
To add a web reference you need to have access to the WSDL file.
You need to do this in 2 steps:
First add a web reference to your project based on the WSDL
Then change the URL of the web reference to match the address of the external service
You can move service URL to web config please refer here.
http://forums.asp.net/p/1268077/2388602.aspx
But if your IP address changes too often (Dynamic IP) I think better your remote network configuration should be changed to have some sort of redirection to your Dynamic IP via a Static IP in your outside network so you can give that Static IP as service URL.
So you don't have to change the web config even too often.
Anyway you Should get advice from a network administrator.

Multiple client endpoints to the same WCF service

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.

Categories