【问题标题】:C# - How to set service reference configuration in a third party applicationC# - 如何在第三方应用程序中设置服务引用配置
【发布时间】:2016-07-12 09:32:04
【问题描述】:

我目前正在用 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 文件中。但是当我构建插件并从第三方应用程序中运行它时,我收到以下消息:

找不到引用合约的默认端点元素 ServiceModel 中的“AuthenticationWebService.AuthenticationEndpoint” 客户端配置部分。这可能是因为没有配置 为您的应用程序找到文件,或者因为没有端点元素 可以在客户端元素中找到与此合同相匹配的内容。

我怀疑错误的原因是第三方应用程序没有配置文件。 您对如何解决这个问题有任何想法吗?

【问题讨论】:

    标签: c# web-services plugins app-config


    【解决方案1】:

    从普通文本文件中读取参数后,您可以在插件代码中显式设置参数(绑定、端点等)...

    这里有一些例子: https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2011-12-14
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      相关资源
      最近更新 更多