简体   繁体   中英

Error while consuming a webservice

I have a webservice provided by a client that I need to consume.

I tested the webservice using WCFTestClient. & I confirmed that the service is working.

Now, I want to consume the webservice using C# code. I added the url of the webservice as a service reference .

I named my service reference as PG_WS . I finished a part of my code.

When I try to debug the code, as soon as I reach the line :

 PG_WS.ServiceSoapClient ws = new PG_WS.ServiceSoapClient();

I get an error saying :

    Message: System.InvalidOperationException: Could not find default endpoint 
element that references contract 'PG_WS.ServiceSoap' 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.
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
       at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
       at System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory()
       at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
       at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
       at System.ServiceModel.ClientBase`1..ctor()

I have been stuck at this point , not knowing what the error means and what I can do next. Please let me know if you have any ideas.

I had to copy the endpoints & the binding tags from my dll and copy them to the webconfig file of my other UI program which calls the web service. This solved my problem.

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