簡體   English   中英

使用 WCF 服務引用為 Office 加載項制作安裝程序

[英]Making an installer for an Office Add-in with a WCF service reference

我正在嘗試構建一系列與 WCF 服務鏈接的 MS Office 加載項。 我在 Visual Studio 上使用 Wix 構建了一個安裝程序,用於安裝加載項和服務主機應用程序。

當我嘗試啟動加載項時,出現如下錯誤:

在 ServiceModel 客戶端配置部分中找不到引用合同“ServiceReference1.IAppCore”的默認端點元素。 這可能是因為找不到您的應用程序的配置文件,或者因為在客戶端元素中找不到與此協定匹配的端點元素。

我用另一個應用程序測試了該服務,它似乎運行得很好,但是我無法讓它與 Office 加載項連接。

有沒有人遇到過這個問題?

您的 office 加載項是否有app.configwebconfig文件? 客戶端對 WCF 的調用需要上述文件中的服務配置,如下面的代碼。

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:21011/" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
        name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>

然后我創建一個呼叫。

ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
            var result = client.Test();
            Console.WriteLine(result);

如果我們的客戶端應用程序沒有appconfig/webconfig文件,我們可以使用Channel Factory庫來調用服務。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
例如,我們可以將上面的調用轉換為下面的調用。

   class Program
    {
        static void Main(string[] args)
        {
//given that we have known the service information, binding type, service endpoint.
            Uri uri = new Uri("http://10.157.13.69:21011");
            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.None;
            ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, new EndpointAddress(uri));
            IService service = factory.CreateChannel();
            var result = service.Test();
            Console.WriteLine(result);
        }
    }

    //service contract is shared between the client-side and the server-side.
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        string Test();
    }

如果問題仍然存在,請隨時告訴我。

感謝您引導我尋找答案。

實際上,在部署加載項后,我意識到它正在嘗試讀取實際 Office 應用程序的 app.config 文件(即 Microsoft Office\\Office16\\EXCEL.EXE.config 等)而不是我自己的

這個問題的解決方案最終非常簡單。

在 Wix Product.wxs 代碼中,清單注冊表項需要以“file:///”為前綴

因此,在我的情況下,它通過更改此條目來解決此問題:


    <Component Id="Excel_Registry_Manifest">
        <RegistryValue 
            Id="RegKey_Manifest_XLS" Root="HKCU"
            Key="Software\Microsoft\Office\Excel\AddIns\ExcelAddIn"
            Name="Manifest"                   
            Value="[INSTALLFOLDER]ExcelAddIn.vsto|vstolocal"
            Type="string" KeyPath="yes" />

對這個:


    <Component Id="Excel_Registry_Manifest">
        <RegistryValue 
            Id="RegKey_Manifest_XLS" Root="HKCU"
            Key="Software\Microsoft\Office\Excel\AddIns\ExcelAddIn"
            Name="Manifest"                   
            Value="file:///[INSTALLFOLDER]ExcelAddIn.vsto|vstolocal"
            Type="string" KeyPath="yes" />

我對所有加載項都這樣做了,現在它們運行得很好。

非常感謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM