C# - 如何在第三方应用程序中设置服务引用配置
C# - How to set service reference configuration in a third party application
我目前正在用 C# 实现第三方应用程序的插件。该插件是一个库 (DLL),它调用一些 Web 服务。因此,我在 Visual Studio 中创建了一个服务引用,它在插件的 app.config
文件中配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticationEndpointImplServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/services/auth"
binding="basicHttpBinding" bindingConfiguration="AuthenticationEndpointImplServiceSoapBinding"
contract="AuthenticationWebService.AuthenticationEndpoint"
name="AuthenticationEndpointImplPort" />
</client>
</system.serviceModel>
</configuration>
我有另一个项目,用于测试插件。当我从该项目调用服务时,它工作正常,前提是我也将相同的配置复制到该项目的 app.config
文件中。但是当我从第三方应用程序中构建插件并 运行 时,我收到以下消息:
Could not find default endpoint element that references contract
'AuthenticationWebService.AuthenticationEndpoint' 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.
我怀疑错误的原因是没有第三方应用程序的配置文件。 你有什么办法解决这个问题吗?
您可以在从普通文本文件读取参数(绑定、端点等)后在您的插件代码中显式设置...
在这里你会找到一些例子:
https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx
我目前正在用 C# 实现第三方应用程序的插件。该插件是一个库 (DLL),它调用一些 Web 服务。因此,我在 Visual Studio 中创建了一个服务引用,它在插件的 app.config
文件中配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticationEndpointImplServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/services/auth"
binding="basicHttpBinding" bindingConfiguration="AuthenticationEndpointImplServiceSoapBinding"
contract="AuthenticationWebService.AuthenticationEndpoint"
name="AuthenticationEndpointImplPort" />
</client>
</system.serviceModel>
</configuration>
我有另一个项目,用于测试插件。当我从该项目调用服务时,它工作正常,前提是我也将相同的配置复制到该项目的 app.config
文件中。但是当我从第三方应用程序中构建插件并 运行 时,我收到以下消息:
Could not find default endpoint element that references contract 'AuthenticationWebService.AuthenticationEndpoint' 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.
我怀疑错误的原因是没有第三方应用程序的配置文件。 你有什么办法解决这个问题吗?
您可以在从普通文本文件读取参数(绑定、端点等)后在您的插件代码中显式设置...
在这里你会找到一些例子: https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx