简体   繁体   中英

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. I built an installer using Wix on Visual Studio which installs the add-ins and the service host app.

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

Has anyone come accross this issue?

Does your office add-in have app.config or webconfig file? The client invocation to the WCF requires the service configuration in the above file, like the below code.

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

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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