简体   繁体   English

C#-如何在第三方应用程序中设置服务参考配置

[英]C# - How to set service reference configuration in a third party application

I am currently implementing a plugin for a third party application in C#. 我目前正在使用C#为第三方应用程序实现插件。 The plugin is a library (DLL) and it calls some Web services. 该插件是一个库(DLL),它调用一些Web服务。 So, I created a Service Reference in Visual Studio, which is configured in the app.config file of the plugin as such: 因此,我在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>

I have another project, that I use for testing the plugin. 我还有另一个项目,用于测试插件。 When I call the service from that project, it works fine, provided I have copied the same configuration to this project's app.config file also. 当我从该项目调用该服务时,只要将相同的配置也复制到该项目的app.config文件中,它就可以正常工作。 But when I build the plugin and run it from within the third party application, I get the following message: 但是,当我构建插件并从第三方应用程序中运行它时,会收到以下消息:

Could not find default endpoint element that references contract 'AuthenticationWebService.AuthenticationEndpoint' in the ServiceModel client configuration section. 在ServiceModel客户端配置部分中找不到引用合同'AuthenticationWebService.AuthenticationEndpoint'的默认终结点元素。 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 suspect the reason for the error is the fact that there is no configuration file for the third party application. 我怀疑该错误的原因是该第三方应用程序没有配置文件的事实。 Do you have any ideas how to work around this? 您有任何解决方法的想法吗?

You could set up your parameters(binding, endpoint, etc.) explicitly in your plugin code after reading them from ordinary text file... 从普通文本文件中读取参数后,可以在插件代码中显式设置参数(绑定,端点等)。

Here you will find some example: https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx 在这里您将找到一些示例: https : //msdn.microsoft.com/zh-cn/library/ms731862(v=vs.110).aspx

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

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