简体   繁体   English

使用 WCF 服务引用为 Office 加载项制作安装程序

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

I'm trying to build a series of MS Office add-ins that all link to with a WCF service.我正在尝试构建一系列与 WCF 服务链接的 MS Office 加载项。 I built an installer using Wix on Visual Studio which installs the add-ins and the service host app.我在 Visual Studio 上使用 Wix 构建了一个安装程序,用于安装加载项和服务主机应用程序。

When I try to launch the add-ins I get an error as follows:当我尝试启动加载项时,出现如下错误:

Could not find default endpoint element that references contract 'ServiceReference1.IAppCore' in the ServiceModel client configuration section.在 ServiceModel 客户端配置部分中找不到引用合同“ServiceReference1.IAppCore”的默认端点元素。 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.这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。

I tested the service with another app and it seems to be running perfectly, however I cannot get it to connect with the Office add-ins.我用另一个应用程序测试了该服务,它似乎运行得很好,但是我无法让它与 Office 加载项连接。

Has anyone come accross this issue?有没有人遇到过这个问题?

Does your office add-in have app.config or webconfig file?您的 office 加载项是否有app.configwebconfig文件? The client invocation to the WCF requires the service configuration in the above file, like the below code.客户端对 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>

Then I create a call.然后我创建一个呼叫。

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

If our client application doesn't own an appconfig/webconfig file, we could use Channel Factory library to call the service.如果我们的客户端应用程序没有appconfig/webconfig文件,我们可以使用Channel Factory库来调用服务。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
For instance, we could transform the above invocation to the below.例如,我们可以将上面的调用转换为下面的调用。

   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();
    }

Feel free to let me know if the problem still exists.如果问题仍然存在,请随时告诉我。

Thanks for directing me towards an answer.感谢您引导我寻找答案。

Actually, after deploying the add-ins I realized it was attempting to read the actual Office app's app.config file (ie Microsoft Office\\Office16\\EXCEL.EXE.config, etc.) instead of my own实际上,在部署加载项后,我意识到它正在尝试读取实际 Office 应用程序的 app.config 文件(即 Microsoft Office\\Office16\\EXCEL.EXE.config 等)而不是我自己的

The solution to this problem is, in the end, extremely simple.这个问题的解决方案最终非常简单。

In the Wix Product.wxs code the manifest registry entry needs to be prefixed with "file:///"在 Wix Product.wxs 代码中,清单注册表项需要以“file:///”为前缀

So in my case it fixed the issue by changing from this entry:因此,在我的情况下,它通过更改此条目来解决此问题:


    <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" />

to this one:对这个:


    <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" />

I did this with all the add-ins and they're running perfectly now.我对所有加载项都这样做了,现在它们运行得很好。

Thanks a lot!非常感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM