2

I have 4 projects in my solution. 2 WCF Service Library projects called GetDetfromDB, ModifyDBService, one console application which has reference of these WCF service libraries and a windows application to call this WCF Service.

I made the reference of the console app in windows app. Now I am able to call the client app from window app.

But now how can I invoke the services which are referred in console app by calling from windows app?

Note: When I press F5 or Debugger-->Start new instance both service runs correctly from my console. I configured all the binding,endpoints address correctly. I want how to call it programmatically.

Here is my console application code:

namespace ServiceHostConsole
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("enter to start");
            Console.Read();

            Type serviceType = typeof(GetDetfromDB.ImpService);
            Type serviceModifyDB = typeof(ModifyDBService.Manipulate);

            ServiceHost host1 = new ServiceHost(serviceModifyDB);
            host1.Open();

            using (ServiceHost host = new ServiceHost(serviceType))
            {
                host.Open();

                Console.WriteLine("The Product Service is available");
                Console.ReadLine(); host.Close();
            }

            Console.WriteLine("Please enter to close modify service");
            Console.Read();
            host1.Close();
        }

        public string returnPath()
        {
            string folder = Environment.CurrentDirectory;
            return folder;
        }
    }
}

From Windows application I am calling like this ....

 public Form1()
 {
      InitializeComponent();

      ServiceHostConsole.Program pb = new ServiceHostConsole.Program();
      Process.Start(pb.returnPath()+ @"\ServiceHostConsole.exe");
 }

Now I am getting the following error when program tries to open my service..

Service 'ModifyDBService.Manipulate' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element

I am suspecting that I am calling blindly the method only and not invoking the service.

Kindly help me to get out of this issue, I have been struggling for the past 5 days for this.

I need to publish my windows application and when i click setup both my windows application and client application with invoked services should open. This is my requirement.

My App.config of ServiceHostConsole look like this,

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="GetDetfromDB.ImpService">
                <endpoint address="http://localhost:8080/MyService" binding="basicHttpBinding"
                    bindingConfiguration="" contract="GetDetfromDB.IGetExpenseValuestype" />
            </service>
            <service name="ModifyDBService.Manipulate">
                <endpoint address="http://localhost:8081/MyService1." binding="basicHttpBinding"
                    bindingConfiguration="" contract="ModifyDBService.IManipulateDB" />
            </service>
        </services>
    </system.serviceModel>
</configuration>
4

1 回答 1

2

不要引用 WCF 服务库。只能从托管服务的项目中引用它们。

相反,您应该使用“添加服务引用”来引用服务

请参阅“如何使用 Web 服务”。

于 2012-06-05T13:59:48.447 回答