Unable to Invoke Custom task referring WCF Service function through MSBuild

為{幸葍}努か 提交于 2019-12-11 15:32:38

问题


I am facing problem while invoking task from MSBuild - Below are the details what I have done -

1)I have C# WCF project having few services running. I hosted these services on Local Host.Service "http://localhost:59605/HotfixDatabaseAccess.svc" running on local machine. and it have function "IHotfixDatabaseAccess.GetComponentDetailsForHF()" which can be called by client which consume this service.

2)I have created another C# library project and I have added "HotfixDatabaseAccess.svc" service reference within It. After adding service it creates App.config file which has all endpoints mentioned for service. App.config - Content

 <?xml version="1.0" encoding="utf-8" ?>
  <configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IHotfixDatabaseAccess" />
            </basicHttpBinding>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IHotfixDatabaseAccess" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:59605/HotfixDatabaseAccess.svc/secure"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHotfixDatabaseAccess"
                contract="HotfixDatabaseAccess.IHotfixDatabaseAccess" name="WSHttpBinding_IHotfixDatabaseAccess">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="http://localhost:59605/HotfixDatabaseAccess.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHotfixDatabaseAccess"
                contract="HotfixDatabaseAccess.IHotfixDatabaseAccess" name="BasicHttpBinding_IHotfixDatabaseAccess" />
        </client>
    </system.serviceModel>
  </configuration>

This C# project contains classes designed as Task, which can be callable from MSBuild project file.

namespace BuildDeliverablesTask
   {
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Text.RegularExpressions;
    using CustomTasks.HotfixDatabaseAccess;
    using Microsoft.Build.Framework;
    using Microsoft.Build.Tasks;
    using Microsoft.Build.Utilities;

    public class BuildDeliverables : Task
    {
         public override bool Execute()
         {
               using (HotfixDatabaseAccessClient hfdbClient = new HotfixDatabaseAccessClient())
               {
                   hfdbClient.GetComponentDetailsForHF(); //Called Service Function.
               }
         }
     }
   }

After building this project it gives "BuildDeliverablesTask.dll" & "BuildDeliverablesTask.dll.config" file. content of "BuildDeliverables.dll.config" is same as that of App.config.

3) My intention is to call this BuildDeliverables Task from MSBuild Proj File. This is MSBuild "BuildDeliverables.proj" file which I have written -

 <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
    <UsingTask AssemblyFile="BuildDeliverablesTask.dll" TaskName="BuildDeliverables" />

    <Target Name="BuildDeliverableSoultions">
    <BuildDeliverables/>  <!-- Task is Called here -->    
    </Target>
   </Project>

4) Now Using MSBuild when I try to invoke "BuildDeliverables.proj" it gives me error InvalidOperationException: Could not find default endpoint element that references contra ct 'HotfixDatabaseAccess.IHotfixDatabaseAccess' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.\r below are error details -

"BuildDeliverables.proj" (default target) (1) ->
(BuildDeliverableSoultions target) ->
  BuildDeliverables.proj(13,5): error : InvalidOperationException: Could not find default endpoint element that references contra
ct 'HotfixDatabaseAccess.IHotfixDatabaseAccess' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint ser
viceEndpoint, String configurationName)\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Confi
guration configuration)\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, Endpo
intAddress address)\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, Endpoint
Address remoteAddress)\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory()\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrai
t)\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()\r
BuildDeliverables.proj(13,5): error :    at System.ServiceModel.ClientBase`1..ctor()\r

Could Some one help me to Resolve this error ?

来源:https://stackoverflow.com/questions/52355977/unable-to-invoke-custom-task-referring-wcf-service-function-through-msbuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!