One WCF service listening to multiple addresses (config only) - wcf

I have an existing Windows service (so no IIS) which hosts a WCF-service.
At this moment it is listening one address: http://xxx/service.svc.
And now I want it to ALSO listen to a second address: http://yyy/service.svc.
I can only modify the configuration, not the sources. The service is running under .NET Framework 4.5.2.
My configuration:
<services>
<service behaviorConfiguration="All" name="MyNamespace.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfig" contract="MyNamespace.IMyService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://xxx/service.svc"/>
</baseAddresses>
</host>
</service>
</services>
What I have tried so far:
Added an extra base address. Then I get an exception: This collection already contains an address with scheme http.
Duplicated the service-element and modify the base address. Exception: A child element named 'service' with same key already exists at the same configuration scope.
If I change the name of both services: Service 'MyNamespace.MyService' has zero application (non-infrastructure) endpoints.
If have read about and tried serviceHostingEnvironment (as suggested in WCF service startup error "This collection already contains an address with scheme http") but only adding that snippet in, does not help. Maybe that is a half step forward, but then I need the second half of that solution.

Related

Unable to configure WCF service for net.tcp in IIS hosting multiple sites

Trying to set up second web site in IIS 7, most/all of the mirrored services function except ones configured for net.tcp. Trying to access the .svc url, I receive the following error:
Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
IIS binding configuration:
Advanced Settings:
Trying to follow answers found on Stack Overflow, none seem to work.
Content of the service's web.config:
<system.serviceModel>
<services>
<service name="ServiceName">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
name="basic" contract="ServiceName.IService" />
<endpoint address="nettcp" binding="netTcpBinding" bindingConfiguration=""
name="netTCP" contract="ServiceName.IService" />
<host>
<baseAddresses>
<add baseAddress="http://staging.localhost/ServiceName" />
<add baseAddress="net.tcp://localhost:8033/ServiceName" />
</baseAddresses>
</host>
</service>
</services>
Is there a trick to the net.tcp bindings? What is correct configuration needed in the web.config?
Thanks!
A screenshot is worth a 1,000 words sometimes. In IIS manager, right-click on the application "ServiceName" and select Manage Application->Advanced Settings. In the advanced settings dialog box, check to see if you've added net.tcp to the Enabled Protocols:

WCF proxy creation at client side with multiple endpoint

i have one service with two endpoint. one endpoint is for wsdual binding and another for tcp binding. when i start my wcf service with wcfsvchost.exe like
WcfSvcHost.exe /service:"C:
\Users\TRIDIP\Documents\Visual Studio 2010\Projects\BBAChatService\BBAChatService\bin
\BBAChatService.dll" /config:"C:\Users\TRIDIP\documents\visual studio 2010\Projects
\BBAChatService\BBAChatService\Web.config"
then my service was started.
the problem is when i try to create proxy at client side after starting service with WcfSvcHost.exe then all endpoints related info gets added in client's config file but i want that when i will create proxy with tcp mex endpoint or mexHttpBinding from client side then only valid endpoint should be added in client's config file not all endpoints. so guide me what to change in my config file at service end. here is my config file at service end....please have look.
<service name="BBAChatService.ChatService" behaviorConfiguration="BBAChatService.ChatServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress ="http://localhost:8732/ChatService.svc/"/>
<add baseAddress ="net.tcp://localhost:7998/ChatService/"/>
</baseAddresses>
</host>
<endpoint name="dual_bind"
address="dual"
binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IChatService"
contract="BBAChatService.IChatService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint name="tcp_bind"
address="tcp"
binding="netTcpBinding"
bindingConfiguration="tcpBinding"
contract="BBAChatService.IChatService">
</endpoint>
<endpoint address="net.tcp://localhost:7996/ChatService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
guide me what to change in my config. thanks
If you expose multiple endpoints in the same service you have multiple ports in WSDL and svcutil (Add service reference) will import configuration for every offered port. WSDL always exposes all defined endpoints for the service and svcutil works with all of them.
You must either manually modify your client config to remove HTTP endpoint configuration on the client side or you must split your service to two different implementations each with single endpoint.

Wcf bindings difference while hosting on windows azure

I have wcf service application which i host on IIS and runs very well.
now i need to transfer the services to windows azure where i host them into web role.
i am not sure but i have heard that there are different bindings for windows azure
example:
azure has different bindings equivalent to basicHttp,WebHttp.
can i know what exactly i need to do to achieve the same.
here is my current service configuration
<service behaviorConfiguration="mybehavior" name="***">
<endpoint address="mobile" behaviorConfiguration="web" binding="webHttpBinding"
contract="*" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:81/Mobile.svc" />
</baseAddresses>
</host>
</service>
what change does this need
Thanks
You can achieve your goal with web.config transofmrations (and here). The issue with Azure is that there is no localhost, nor 127.0.0.1 there (well, there might be, but nothing is being routed to that local loop address). All you have to do is to change the baseAddress.
In order to change the baseAddress you may do any of the following:
use web.config transofmrations and in your web.Release.config put your azure domain name in the base address (http://yourapp.cloudapp.net/, or your custom domain if you are using one)
programatically bind the wcf service using the DIP of the role instance (check this and that questions for more information)

WCF Basics - Endpoints

I'm wondering about the address="" section in the web.config file
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" name="user">
<endpoint address="" behaviorConfiguration="ptUserAspNetAjaxBehavior" binding="webHttpBinding" contract="IUser" />
</service>
</services>
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" name="controller">
<endpoint address="" behaviorConfiguration="ptUserAspNetAjaxBehavior" binding="webHttpBinding" contract="Icontroller" />
</service>
</services>
I'm adding a second service that I will be calling via jQuery. My first service worked great. As you can see the endpoint address is blank. I'm adding the second service and I'm wondering first if I'm doing it correctly? Can I create a new service tag using the same behaviorConfiguration, and binding but with a different contract?
This spawned another question about the address in the web.config file.
Why does it work when it is = "" and why would I want to use an address?
It will work with address="" when
you host your service in IIS and basically IIS's virtual directory dictates the URL of your service (the vdir where your *.svc file exists). Thus if you have two separate services, with two separate *.svc files, then each entry in the configuration can have an address="" setting. But you cannot have two endpoints for the same service and both have the empty address attribute
or:
you have a base address defined for your service in your config and thus that endpoint will use that base address for its service address

WCF wsHttpBinding and BasicHttpBinding in same WCF Service Application

I have been told that wsHttpBinding does not support older clients that still need to use older version of SOAP. I want to add a BasicHttpBinding endpoint in the same WCF Service Application so that clients can use either endpoint depending on their technology they are running. I am confused as to what the address to use for each of them. The default wsHttpBinding has no address set. What should the address be for BasicHttpBinding endpoint? Shouldn't the address for the wsHttpBinding be (for my example) http://localhost/WcfService1/Service1.svc ?
There's two things you need to consider here:
if your hosting in IIS (or WAS as part of IIS7), you cannot set a base address - the base address for your service will be the virtual directory where the MyService.svc file lives. You can still set relative addresses, though
if you self-host, you typically will add base addresses in your config, so you can spare yourself having to spell out the entire address all the time (but you can - if you wish to do so).
So if you have your MyService.svc inside a virtual directory called MyApp on your localhost machine, and then use this config:
<service name="MyService" behaviorConfiguration="Default">
<endpoint
address="wsHttp"
binding="wsHttpBinding"
contract="IMyService" />
<endpoint
address="basic"
binding="basicHttpBinding"
contract="IMyService" />
</service>
then your "old-style" basicHttp service will be reachable at:
http://localhost/MyApp/MyService.svc/basic
and your new wsHttp driven service will be reachable at:
http://localhost/MyApp/MyService.svc/wsHttp
You can name those relative addresses (anything after .../MyApp/MyService.svc) anything you like - just make sure they're different from one another.
Hosting in IIS --> location (virtual directory) of your *.svc file becomes your base address.
If you self-host your service inside a console app or a Windows NT Service, you get to set your base addresses yourself:
<services>
<service name="MyService" behaviorConfiguration="Default">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8185/Services/" />
</baseAddresses>
</host>
</service>
</services>
Now in this case, your "old-style" basicHttp service will be reachable at:
http://localhost:8185/Services/basic
and your new wsHttp driven service will be reachable at:
http://localhost:8185/Services/wsHttp
You can define a base address for each of the transports, e.g. one for http://, one for net.tcp:// and so on.
And of course, if you really must, you can also define your complete addresses inside your <endpoint> element for each of the service endpoints - this gives you total flexibility (but only works in self-hosting scenarios).
Marc
In WCF you have a base address and an enpoint address, in your case you can do something like this:
<service name="WcfEndpoints.Service1" behaviorConfiguration="WcfEndpoints.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="new" binding="wsHttpBinding" contract="WcfEndpoints.IService1" />
<endpoint address="old" binding="basicHttpBinding" contract="WcfEndpoints.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
Note you will need additional work for the basicHttpBinding endpoint to work with older (asmx) clients
http://msdn.microsoft.com/en-us/library/ms751433.aspx