Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

When we are creating a WCF service and Hosting using IIS with single service, then it works fine.

When I have two service implemented and host then its not working as expected.

I have two services as,

1) Addition Service

2)Subtraction Service

<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceIIS.AdditionService" CodeBeind="CalcService.svc.cs" %>


what ever service name I mention in the service.svc file is hosted and available for external to consume.

I want to know how to create the client function and switch between two service to be exposed.
Posted
Comments
Sergey Alexandrovich Kryukov 30-Oct-13 1:19am    
I understand: if you overcome this problem, it will open the door to multiplication and division services, to create a service field. :-)
I wonder why...
—SA
[no name] 30-Oct-13 1:23am    
Yes, when we have multiple service. I have option to expose only one service. I want to know how to use some Client proxy to expose multiple services.

Thanks for your Reply, Please find my comments
I have a single .SVC file which has two service class [Addition/Subtraction] Service.
I have two end points for these two services.
<services>
  <service name="AdditionService">
    <endpoint address="http://localhost:8080/AdditionService">
              binding="basicHttpBinding"
              contract="IService" />
  </endpoint></service>
  <service name="SubtractService">
    <endpoint address="http://localhost:8080/SubtractService">
              binding="wsHttpBinding"
              contract="IService" />
  </endpoint></service>
</services>

I want to know, is the way I am approaching is fine or is there any appropriate way of approach, since I am novice to WCF.
 
Share this answer
 
v2
C#
public class InternalService : IService
    {
        public string StartServer()
        {
            return "\n\n@@@ Internal Server Started!";
        }
    }


    public class ExternalService : IService
    {
        public string StartServer()
        {
            return "\n\n$$$ External Server Started!";
        }
    }


    public class CustomServiceHostFactory : ServiceHostFactory
    {
        protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            ManualProxy.TargetFactory = () => new InternalService();
            return base.CreateServiceHost(typeof(ManualProxy), baseAddresses);
        }

    }

    public class ManualProxy : IService
    {
        private readonly IService _target;

        public static Func<object> TargetFactory;

        public ManualProxy()
        {
            _target = (IService)TargetFactory();
        }
        public ManualProxy(Func<object> TargetFactory)
        {
            _target = (IService)TargetFactory();
        }

        public string StartServer()
        {
            return _target.StartServer();
        }
    }
 
Share this answer
 
How have you hosted these two services. I mean, are you using two different .svc file or two different end points. If two different end points, then you can switch between two services using end point name at the client side.
If you are using two .svc file then you will have two different service which you can call separately.
 
Share this answer
 
Comments
[no name] 30-Oct-13 6:19am    
I have a single .SVC file which has two service class [Addition/Subtraction] Service.
I have two end points for these two services.

<services>
<service name="AdditionService">
<endpoint address="http://localhost:8080/AdditionService"
="" binding="basicHttpBinding" contract="IService">


I want to know, is the way I am approaching is fine or is there any appropriate way of approach, since I am novice to WCF.

<service name="SubtractService">
<endpoint address="http://localhost:8080/SubtractService"
="" binding="wsHttpBinding" contract="IService">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900