Невозможно вызвать пользовательскую задачу, ссылающуюся на функцию службы WCF через MSBuild - PullRequest
0 голосов
/ 16 сентября 2018

Я столкнулся с проблемой при вызове задачи из MSBuild - Ниже приведены подробности того, что я сделал -

1) У меня есть проект C # WCF с несколькими запущенными сервисами. Я размещал эти службы на Local Host.Service "http://localhost:59605/HotfixDatabaseAccess.svc", работающем на локальной машине. и у него есть функция "IHotfixDatabaseAccess.GetComponentDetailsForHF ()", которая может быть вызвана клиентом, который использует этот сервис.

2) Я создал другой проект библиотеки C # и добавил в него ссылку на службу «HotfixDatabaseAccess.svc». После добавления сервиса он создает файл App.config, в котором есть все конечные точки, указанные для сервиса. App.config - Содержимое

 <?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>

Этот проект C # содержит классы, разработанные как Task, которые можно вызывать из файла проекта MSBuild.

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.
               }
         }
     }
   }

После сборки этого проекта он выдает файл "BuildDeliverablesTask.dll" и "BuildDeliverablesTask.dll.config". содержимое файла "BuildDeliverables.dll.config" такое же, как содержимое файла App.config.

3) Мое намерение - вызвать эту задачу BuildDeliverables из файла MSBuild Proj. Это файл MSBuild "BuildDeliverables.proj", который я написал -

 <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) Теперь при использовании MSBuild при попытке вызвать BuildDeliverables.proj выдается ошибка InvalidOperationException: не удалось найти элемент конечной точки по умолчанию, который ссылается на ct 'HotfixDatabaseAccess.IHotfixDatabaseAccess' в разделе конфигурации клиента ServiceModel. Это может быть связано с тем, что для вашего приложения не найден файл конфигурации или из-за того, что ни один элемент конечной точки, соответствующий этому контракту, не найден в клиентском элементе. \ R ниже приведены подробности ошибки -

"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

Может ли кто-нибудь помочь мне разрешить эту ошибку?

...