I hope this is a quick question. I have a WCF service running on IIS port 4040. I have added the following headers to this service
4040 (non load balanced domain)
4040 localhost
So locally I can reference this service as http://localhost:4040/service.svc and also by the fully qualified domain name. This is no problem for all the services on this machine, I can reference everything by localhost:4040
The issue comes when I try to access it from another server (as we have other apps that need to consume the service)
I get a 404 error, and was wondering whether the service is defaulting to being exposed on localhost loopback (127.0.0.1) therefore cannot be accessed.
The endpoint is defined as such:
<service behaviorConfiguration="ClaimChaseBehavior"
name="Modules.EClaims.ClaimChase">
<endpoint address=""
binding="basicHttpBinding"
contract="Domain.EClaims.DataInterfaces.IClaimChase" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
Notice I don't define an address. The reason for this is to allow us to have a common config file (we are trying to get around defining machine domains/addresses and thus multiple configs)
Is there a way to make the WCF default to the machine IP instead of the loopback connector without defining the actual domain name
Hope this makes sense
Regards
Richard
When you're hosting your service in IIS, the address of the service is defined and controlled by the location of your *.svc file - you cannot override that by defining base addresses or explicit address on your service endpoints.
The service address will always be:
http://machinename/VirtualDirectory/YourService.svc
Marc
Check your web config. Have you spesified that the address of the service is localhost?
EDIT:
On second thoughts, it looks like a firewall problem, is port 4040 blocked by a local firewall?
Related
I read all over the msdn where it says to enable port sharing : The port sharing service should be started and my net.tcp binding should specify 'portSharingEnabled = True'.
I also see that net.tcp binding documentation shows the default value for portsharing as false.
But in my VS 2013, WIN 7 machine, I have a console app hositing many services and I am able to run it from VS without any issues. My servichost is able to host more than 10 services with the same port. What am I missing to understand ? Any ideas ?
I use this endpoint followed by servicename for all my services:
<service name="Lookup" behaviorConfiguration="">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/"/>
</baseAddresses>
</host>
<endpoint
name="IEntitiesLookup"
binding="netTcpBinding"
address="LookupService"
contract="ILookup" />
</service>
I managed to clear my understanding on port sharing to an extent. But would be happy for more thoughts on this.
I managed to find the reason behind the above scenario. Within a process, I am able to host several endpoints which shares the same port. This does not need port sharing to be enabled. But if I have another process which tries to host some services with same port numbers, then an exception for 'ports already in use' happens. In this case, we then need to enable port sharing in the binding of all the endpoints in both the service host processes and start the PortSharing service.
I believe this boils down to the understanding that in the transport layer, the port numbers are tied to the process.
In my App.config, i have this base address specified ("jerrycan" is the name of my computer):
<service behaviorConfiguration="helloWorldServiceBehavior" name="OpdService.OpdService">
<endpoint address="/service" binding="netTcpBinding" bindingConfiguration="NewBinding0"
name="MainEndPoint" contract="OpdService.IOpdService">
<identity>
<dns value="jerrycan" />
</identity>
</endpoint>
<endpoint kind="udpDiscoveryEndpoint" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://jerrycan:8000" />
<add baseAddress="http://jerrycan/service" />
</baseAddresses>
<timeouts openTimeout="00:00:15" />
</host>
</service>
Everything works fine until I run service on other computer — clients can find service through UDP discovery, but aren't able to connect, as service continues to send old address. When I change "jerrycan" to "localhost", only local clients are able to connect to service (but on any computer). Any clients on other computers try to connect to "localhost" with no success.
So what should I use as host address if I want to be able to run service on different computers without recompile? Should I store address somewhere in config file for every computer, or should I change address in runtime? I think, I'm missing something simple and fundamental here.
Or maybe I should use localhost (as in many wcf samples) and it's my client connection code who brings the problems:
EndpointAddress endpointAddress = findResponse.Endpoints[0].Address;
OpdChannelFactory = new DuplexChannelFactory<OpdServiceReference.IOpdService>(CallbackHandler,
new NetTcpBinding("MainEndPoint"), endpointAddress);
Again, when I use "localhost" as base address, "localhost" comes as endpoint address in findResponse.
Edit:
It seems like I found solution here: http://btw-blog.blogspot.com/2011/02/dynamic-base-address-for-wcf-service.html
The point is to replace host name in base address with * symbol (wildcard). It will be changed with actual host name in run time.
Haven't tested everything yet, but looks like it actually works.
It seems like I found solution here: http://btw-blog.blogspot.com/2011/02/dynamic-base-address-for-wcf-service.html
The point is to replace host name in base address with "*" symbol (wildcard). It will be changed with actual host name in run time.
Tested it and it worked great.
Right now your service endpoint address is:
net.tcp://jerrycan:8000/service
When you create clients on the computer which is hosting the service (jerrycan-pc) of course the local clients will be able to access the service by referencing
net.tcp://localhost:8000/service
and obviously other clients (on other computers on your network) can not connect to the service if they try to contact localhost, because the endpoint: net.tcp://localhost:8000/service, is calling the local computer which in this case is not hosting the service (only for jerrycan-pc). If jerrycan-pc is hosting the service, clients on jerrycan-pc can call the service by referencing localhost, but clients on say mike-pc must either try to call jerrycan-pc or jerrycan-pc's IP. If you change the endpoint in your service configuration to your service hosts IP or even computer name, and reference the service on other computers using the IP of the service host/computer name then they will be able to access it. For example if jerrycan-pc is hosting the service and it has an IP of 192.168.1.5, your clients can consume the service by referencing this endpoint:
net.tcp://192.168.1.5:8000/service
So in your service config change localhost to the IP address or PC name and try to contact that address on your clients instead of contacting localhost.
I'm trying to get my head around the addressing of WCF services.
We have a client-server setup where the server occasionally (maybe once a day) needs to push data to each client. I want to have a lightweight WCF listener service on each client hosted in an NT service to receive that data. We already have such an NT service setup hosting some local WCF services for other tasks so the overhead of this is minimal.
Because of existing legacy code on the server I believe the service needs to be exposed as ASMX and use basicHttpBinding to allow it to connect.
Each client is registered on the server by the user (they need to configure them individually) so discovery is not the issue.
My question is, how does the addressing work? I imagine the user entering the client's address on the server in the form
http://0.0.0.0/MyService
or even
http://hostname/MyService
If so, how do I configure the client service in its App.config? Do I use localhost?
If not then what is the reccommended way of exposing the service to the server?
Note:
I don't want to host in IIS as that adds extra requirements to the hardware required for the client.
The clients will be almost certainly located on LANs, not over the public internet
You configure the base address of the service like so:
<system.serviceModel>
<services>
<service name="Ns.FooService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9999" />
</baseAddresses>
</host>
<endpoint
address="/foo"
binding="basicHttpBinding"
contract="Ns.IFooContract" />
</service>
</services>
</system.serviceModel>
And then your service could be accessible through http://servename:9999/foo. You may take a look at this article for more information.
I'm connecting a WCF client to a group of services all implementing the same contract and all at the same host. I was hoping that there would be a way to combine the endpoint definitions to cut down on configuration clutter. I also would rather not do it programmaticly - just by configuration. Right now, my config has this repeated many times:
<endpoint address="http://hostname/ServiceA.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyBinding"
contract="ServiceReference.ISearchService" name="ServiceA">
</endpoint>
<endpoint address="http://hostname/ServiceB.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyBinding"
contract="ServiceReference.ISearchService" name="ServiceB">
</endpoint>
// continued for ServiceC, ServiceD, etc
For server configurations, there is some notion of "baseAddressPrefixFilters" that can be used for this purpose - is there anything for client configuration?
There is the concept of a base address in WCF - unfortunately, that only works if you self-host, e.g. host your service in a console app or NT service. However, that only works on the server side - there's nothing similar on the client side. On the client side, you always have to define the complete, full service address your endpoint should connect to.
If you host in IIS, your service address is determined by the server name, the virtual directory (and possibly subdirectories under that) and the name of the *.svc file used to host the service in IIS. This is a fixed system convention and you cannot influence it, unfortunately (.NET 4 will bring some remedy to that).
We have a WCF service deployed on a Windows 2003 server that is exhibiting some problems. The configuration is using wsHttpBinding and we are specifying the IP address. The services is being hosted by a Windows Service.
When we start the service up, most of the time it grabs the wrong IP address. A few times it bound to the correct address only to drop that binding and go to the other address (there are 2) bound to the NIC after processing for a short while.
It is currently using port 80 (we've configured IIS to bind to only 1 address via httpcfg) although we have tried it using different ports with the same results.
When the Windows Service starts hosting the WCF service, the properties show that it is being bound to the correct address; however, tcpview shows that it is indeed listening on the incorrect address.
Here is the portion of the config that sets up tehe baseAddress. The one that gets bound to ends up being .4 instead of .9
<services>
<service name="Service.MyService"
behaviorConfiguration="serviceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://xx.xx.xx.9:80/" />
</baseAddresses>
</host>
<endpoint address="MyService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IMyService"
contract="Service.IMyService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
Is there some other configuration that needs to be set?
Is there a tool that can help track down where this is getting bound to the wrong address?
Your WCF configuration looks OK to me. This might be an issue with the binding order of your NIC cards. Make sure that the NIC with correct address is first. Here is an article that discuss how to set and view nic binding orders:
http://theregime.wordpress.com/2008/03/04/how-to-setview-the-nic-bind-order-in-windows/
The issue seems to be ISS related. Here is the description about the error your getting from http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/ddf72ae0-aa1e-48c9-88d1-10bae1e87e4f.mspx?mfr=true
This error is logged to the event log when HTTP.sys parses the IP inclusion list and finds that all of the entries in the list are invalid. If this happens, as the description in Table 11.15 notes, HTTP.sys listens to all IP addresses.
You can also check the following thread which talks about a similiar issue
http://www.webhostingtalk.com/showthread.php?t=534174
Hope this helps.
We had the same issue and this feature helped us to solve our problem :
http://msdn.microsoft.com/en-us/library/system.servicemodel.hostnamecomparisonmode.aspx
Hope this help.
More information: I removed the xx.xx.xx.4 IP address from the NIC altogether and turned off IIS. Now when I try to start the service it fails and I find this in the System event log.
Description:
Unable to bind to the underlying transport for xx.xx.xx.4:80. The IP Listen-Only list may contain a reference to an interface which may not exist on this machine. The data field contains the error number.
My configuration file still has the xx.xx.xx.9 baseAddress setting.
One more piece of informatoin. If we change the binding to use NetTcp instead of WsHttp it binds to the correct address on port 80. Changing it back to WsHttp it goes back to the incorrect IP address.
BaseAddress is ignored. You need to set a host header under IIS.