简体   繁体   中英

'System.InvalidOperationException' when LINQ to SQL using WCF on WP8

This is the code where the exception occurs:

public Listado()
    {
        InitializeComponent();

        ListadoWebService();
    }
    public void ListadoWebService()
    {
       // InitializeComponent();
        ServiceTours.ServiceToursClient cl = new ServiceTours.ServiceToursClient(); 
        cl.ListadoCompleted += new EventHandler<ListadoCompletedEventArgs>(Listado2);
        cl.ListadoAsync();
    }
    private void Listado2(object sender, ListadoCompletedEventArgs e)
    {
        listB.ItemsSource = e.Result; // listB is ListBox in WP8
    }

I get following Exception:

An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.ni.dll but was not handled in user code

I would like to say that I directly followed this tutorial on MSDN

So the final Service Reference url is: http:// IP /WcfTours/ServiceTours.svc as it should be. //99.99.99 represents IP

World Wide Web Services (HTTP) in Allow an app through Windows Firewall is allowed for domain public and private .

Virtual Directory is created.

Will somebody please help me with setting the endpoint please ?

Exception message:

{System.InvalidOperationException: An endpoint configuration section for contract 'ServiceTours.IServiceTours' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name. at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard) at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) at System.ServiceModel.ChannelFactory {System.InvalidOperationException: An endpoint configuration section for contract 'ServiceTours.IServiceTours' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name. at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard) at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) 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.EndpointTrait 1.CreateSimplexFactory() at System.ServiceModel.ClientBase 1.CreateChannelFactoryRef(EndpointTrait 1 endpointTrait) at System.ServiceModel.ClientBase 1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase 1..ctor() at PhoneApp1.ServiceTours.ServiceToursClient..ctor() at PhoneApp1.Listado.ListadoWebService() at PhoneApp1.Listado..ctor()}

As soon as you add a Web Service reference in your project a new ServiceReferences.ClientConfig file is created in the root folder of your project. Open it somewhere and look for:

<client>
    <endpoint .... name="endpointName" />
<endpoint .... name="endpointName2" />
</client>

In your case you have more than one records there. so select the appropriate and pass the name into contructor of ServiceToursClient.

new ServiceToursClient("endpointName")

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