問題描述
.NET C# Office Shared Add In WCF Service 引用異常 (.NET C# Office Shared Add In WCF Service reference exception)
I have created an office shared add in using Visual Studio 2010 .NET 4.0. This add in references a WCF service. When creating an instance of the WCF service client, i get the following exception:
Could not find default endpoint element that references contract 'Services.IBusinessLogicLayerMetaData' 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 am not sure how to resolve this. My app.config looks like this:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IBusinessLogicLayerMetaData" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="1048576000" messageEncoding="Text" textEncoding="utf‑8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://10.181.9.47:8000/DeutscheBank.WindowsServices.DataSOA/BusinessLogicLayerMetaDataService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IBusinessLogicLayerMetaData" contract="Services.IBusinessLogicLayerMetaData" name="WSHttpBinding_IBusinessLogicLayerMetaData" />
</client>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
‑‑‑‑‑
參考解法
方法 1:
Hope this helps someone.
I resolved this issue by copying the add in config file and dll to the office directory. I also made a copy of the config file and renamed it to "OfficeApplication".exe.config.
"OfficeApplication" is the office app that you would like the add in to work with.