Mutiple http base address for self hosted WCF service? - c#

I have a WCF service that has one http endpoint,
I would like to add another http endpoint address with a different binding.
The service is not hosted in IIS and hence setting the multipleSiteBindingsEnabled
is of no use.
Am trying something like this.
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="ServiceBehaviorConfiguration"
name="ServerService">
<endpoint address="http://localhost:6732/ServerService" binding="webHttpBinding" behaviorConfiguration="webby"
contract="IClientAppContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://localhost:800/ServerService" binding="basicHttpBinding"
contract="IClientAppContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:800/ServerService" />
<add baseAddress="http://localhost:6732/ServerService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>

Try something like the config shown below. It exposes multiple endpoints through a single port but I'm sure this pattern of configuration is supported by WCF.
<services>
<service behaviorConfiguration="ServiceBehaviorConfiguration"
name="ServerService">
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="webby"
contract="IClientAppContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="basic"
binding="basicHttpBinding"
contract="IClientAppContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:800/ServerService" />
</baseAddresses>
</host>
</service>
</services>

You could create two services that each have their own different baseAddress, but their internal endpoints are identical.

Related

Configure single endpoint for all WCF services offerend in project?

In my WCF project, I have two services Products and Customers. Both these services have separate interface and implementation .cs files. In App.Config I could see the below,
<service name="DemoProj.Services.ProductService">
<endpoint address="" binding="basicHttpBinding" contract="DemoProj.Services.Interfaces.IProductService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/DemoProj/Service/ProductService/" />
</baseAddresses>
</host>
</service>
<service name="DemoProj.Services.CustomerService">
<endpoint address="" binding="basicHttpBinding" contract="DemoProj.Services.Interfaces.ICustomerService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/DemoProj/Service/CustomerService/" />
</baseAddresses>
</host>
</service>
When the client consumes this WCF service, it will require both Products and Customers service.
My question is, I will have many more services and the App.config is going to be big with lots of endpoints. In my current scenario, I will need only one contract, binding, address for all my services like Products, Customers and so on. I need to only configure one endpoint that is shared by all the services I expose to my client.
I understand, it is by WCF design where it is more flexible to have different configurations for different services offered. But in my case i don't require like that. I want to make my App.config simple with only one endpoint.

WCF-Communication with multiple endpoints

I have a problem. I try to build a WCF Communication with multiple entpoints. But it never works and it displays a ErrorMessage like this:
The contract name '{0}' could not be found in the list of contracts implemented by the service '{1}'.
And this is my Config-File:
*
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="MwWcfLibrary.Service">
<endpoint address="net.tcp://localhost:8733"
binding="netTcpBinding"
bindingConfiguration=""
bindingName="Action"
name="ActionInterface"
contract="MwWcfLibrary.Actions.Interfaces.IAction">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
bindingConfiguration=""
name="Mex"
contract="IMetadataExchange" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="LifeSignInterface"
bindingName="LifeSign"
contract="MwWcfLibrary.LifeSign.Interfaces.ILifeSign" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="DataInterface"
bindingName="Data"
contract="MwWcfLibrary.Notification.Interfaces.IData">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="PublicDataInterface"
bindingName="PublicData"
contract="MwWcfLibrary.PublicData.Interfaces.IPublicData" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="PublicStateInterface"
bindingName="PublicState"
contract="MwWcfLibrary.PublicState.Interfaces.IPublicState" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8733//MwWcfLibrary" />
</baseAddresses>
<timeouts closeTimeout="00:00:30" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
*
Does someone figure out if i configured something wrong?
Kind Regards.
EDIT
You either haven't implemented one of these interfaces:
MwWcfLibrary.Actions.Interfaces.IAction, MwWcfLibrary.LifeSign.Interfaces.ILifeSign, MwWcfLibrary.PublicData.Interfaces.IPublicData and MwWcfLibrary.PublicState.Interfaces.IPublicState
or one or more of them is not decorated with the [ServiceContract] attribute
Include the actual error in your question instead of '{0}', you'll see that some of your contracts have not been implemented by the class Service which should look like this (at least):
class Service : IAction, ILifeSign, IPublicData, IPublicState
{
// implementation
}
Also, your address attributes don't appear to be correct, since you've defined a base address ending with a segment //Mww... yet in your endpoints the address is shorter than the base address. The endpoint addresses can just be relative like "Service".
Previously
The Service element refers to a class that's an implementation of a ServiceContract interface, which is what goes into the endpoint contract attribute. Verify the fully qualified names of your interfaces and classes in theses attributes.
From looking at your configuration file, you are saying that the class MwWcfLibrary.Service implements the ([ServiceContract] decorated) interfaces called MwWcfLibrary.Actions.Interfaces.IAction, MwWcfLibrary.LifeSign.Interfaces.ILifeSign, MwWcfLibrary.PublicData.Interfaces.IPublicData and MwWcfLibrary.PublicState.Interfaces.IPublicState
That seems to be in error. Do you mean to have two services, each with a separate endpoint?

Connect via Java client to WCF Service

I have WCF service which has 2 endpoints: wsHttpBinding and basicHttpBinding. I can connect to each endpoint via C# client.
My Wcf Service configuration
<service behaviorConfiguration="App.ServiceBehavior"
name="MyService">
<endpoint address="/ws" binding="wsHttpBinding" bindingConfiguration="httpBindingForWs"
contract="Namespace.IMyService">
<identity>
<dns value="127.0.0.1" />
</identity>
</endpoint>
<endpoint address="/basic" binding="basicHttpBinding" bindingConfiguration="httpBindingForBasic"
contract="Namespace.IMyService">
<identity>
<dns value="127.0.0.1" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:12000/MyService" />
</baseAddresses>
</host>
</service>
I can generate wsdl in Java. Can you show me sample code, how can I consume basicHttpBinding in Java?
you can consume the webservice using Java there are different frameworks to make your job easier, like AXIS and Apache CXF
Look at following article for more pointers on same
Consuming WCF services with Java

web service endpoint wrong address

<services>
<service name="WebServices.Service" behaviorConfiguration="WebServices.ServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="http://ip/Service.svc" binding="wsHttpBinding" contract="WebServices.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
but my endpoint is still
svcutil.exe http://server-iis/Service.svc?wsdl. How to change server-iis to my IP?
Try solution suggested in here.
I'am not sure but I hope this suggestion helps you.

1 end point multiple servicecontracts - wcf?

I created a service which allows clients to search for user information. This is exposed as an interface ISearchUsers.
I used this article as a base but to no avail: Not sure if this is the way to go
link text
Now I want to create and expose an interface called ICreateUser and i assumed that i had to create a new endpoint , basicHttp binding and used the article above.
This is part of my config:
<services>
<service behaviorConfiguration="Service.Service1Behavior"
name="Service.SearchService">
<clear />
<endpoint binding="basicHttpBinding" bindingConfiguration="WsHttpMtomBinding"
contract="Service.ISearchService" listenUriMode="Explicit">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
listenUriMode="Explicit">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Service/Service1/" />
</baseAddresses>
</host>
</service>
</services>
You can extend your current service class which implements ISearchUser and let it implement ICreateUser as well - in that case, you could add a second endpoint to your service config:
<services>
<service name="Service.SearchService"
behaviorConfiguration="Service.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Services/" />
</baseAddresses>
</host>
<endpoint
address="SearchUser"
binding="basicHttpBinding" bindingConfiguration="WsHttpMtomBinding"
contract="Service.ISearchService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="CreateUser"
binding="basicHttpBinding" bindingConfiguration="WsHttpMtomBinding"
contract="Service.ICreateUserService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
One thing that most likely doesn't work in your case is the fact you pick "basicHttpBinding" as your binding, but the bindingConfiguration seems to indicate WsHttpBidning..... those need to match and thus should probably be:
<endpoint
address="CreateUser"
binding="basicHttpBinding" bindingConfiguration="basicHttpMtomBinding"
contract="Service.ICreateUserService">
Marc

Categories