在WP8上使用WCF的LINQ to SQL时出现'System.InvalidOperationException'

时间:2013-10-15 11:08:05

标签: c# wcf linq-to-sql windows-phone-8

这是发生异常的代码:

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
    }

我得到以下例外:

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

我想说我直接在MSDN

上遵循了本教程

所以最终的服务参考网址是:http:// IP /WcfTours/ServiceTours.svc应该是这样。 //99.99.99代表IP

World Wide Web Services (HTTP) Allow an app through Windows Firewalldomain允许public中的

private

Virtual Directory已创建。

有人请帮我设置endpoint吗?

异常消息:

{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)    在System.ServiceModel.EndpointTrait 1.CreateSimplexFactory() at System.ServiceModel.ClientBase 1.CreateChannelFactoryRef(EndpointTrait 1 endpointTrait) at System.ServiceModel.ClientBase 1.InitializeChannelFactoryRef()    在System.ServiceModel.ClientBase 1..ctor() at PhoneApp1.ServiceTours.ServiceToursClient..ctor() at PhoneApp1.Listado.ListadoWebService() at PhoneApp1.Listado..ctor()}

1 个答案:

答案 0 :(得分:1)

只要在项目中添加Web Service引用,就会在项目的根文件夹中创建一个新的ServiceReferences.ClientConfig文件。在某处打开并寻找:

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

在您的情况下,您有多个记录。所以选择合适的名称并将名称传递给ServiceToursClient的构造函数。

new ServiceToursClient("endpointName")