简体   繁体   中英

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#. The plugin is a library (DLL) and it calls some Web services. So, I created a Service Reference in Visual Studio, which is configured in the app.config file of the plugin as such:

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

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