Failed to consume WS SOAP from VS2015 with C #

1

Dear

Inside VS 2015 with C # I created a dll project in which I make a reference to a WS from one of our suppliers, after that I created a unit testing project where I call the service without further ado with its constructor

 ServiceHotelClient serviceHotelClient = new  ServiceHotelClient();

I added the necessary namespace with using and it turns out that I have the following error

El código de usuario no controló System.InvalidOperationException
    HResult=-2146233079
    Message=No se encontró el elemento de extremo predeterminado que hace referencia al contrato 'WSServiceReference.IServiceHotel' en la sección de configuración de cliente de ServiceModel. La razón puede ser que no se encontró ningún archivo de configuración para la aplicación o que no se encontró ningún elemento de extremo correspondiente a este contrato en el elemento de cliente.
    Source=System.ServiceModel
    StackTrace:
        en System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
        en System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
        en System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
        en System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
        en System.ServiceModel.ChannelFactory'1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
        en System.ServiceModel.ConfigurationEndpointTrait'1.CreateSimplexFactory()
        en System.ServiceModel.ConfigurationEndpointTrait'1.CreateChannelFactory()
        en System.ServiceModel.ClientBase'1.CreateChannelFactoryRef(EndpointTrait'1 endpointTrait)
        en System.ServiceModel.ClientBase'1.InitializeChannelFactoryRef()
        en System.ServiceModel.ClientBase'1..ctor()
        en BusinessAgent_WS.WSServiceReference.ServiceHotelClient..ctor() en D:\Codigo\BusinessAgent_WS\BusinessAgent_WS\Service References\WSServiceReference\Reference.cs:línea 1630
        en Netactica.Net.Core.Source.WS.WSManager..ctor(Credential credential) en D:\Codigo\BusinessAgent_WS\BusinessAgent_WS\WSManager.cs:línea 24
        en UnitTestProject1.UnitTest1.TestMethod1() en D:\Codigo\BusinessAgent_WS\UnitTestProject1\UnitTest1.cs:línea 34
    InnerException:

I would appreciate your support

    
asked by Hoscanoa 06.07.2017 в 23:06
source

1 answer

1

You have to copy the configuration section that was created in the app.config of the project class library to the config of the test project

Remember that the configuration is read automatically from the config of the project that starts the execution, in this case the unit testing, it is there where you must have the configuration section that makes use of the proxy that is created when you perform the web reference.

In the app.config of the project Class Library you will see a section serviceModel that is what you should take the app.config but the project unit test , since from there the configuration will raise the dll when you execute

    
answered by 06.07.2017 / 23:22
source