【问题标题】:'System.InvalidOperationException' when LINQ to SQL using WCF on WP8'System.InvalidOperationException' 当 LINQ to SQL 在 WP8 上使用 WCF 时
【发布时间】:2013-10-15 19:46:25
【问题描述】:

这是发生异常的代码:

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

Allow an app through Windows Firewall 中的World Wide Web Services (HTTP) 允许用于domain publicprivate

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.ChannelFactory1..ctor(字符串端点配置名称,端点地址远程地址) 在 System.ServiceModel.EndpointTrait1.CreateSimplexFactory() at System.ServiceModel.ClientBase1.CreateChannelFactoryRef(EndpointTrait1 endpointTrait) at System.ServiceModel.ClientBase1.InitializeChannelFactoryRef() 在 System.ServiceModel.ClientBase1..ctor() at PhoneApp1.ServiceTours.ServiceToursClient..ctor() at PhoneApp1.Listado.ListadoWebService() at PhoneApp1.Listado..ctor()}

【问题讨论】:

  • 请告诉我们异常信息。
  • @DanielHilgarth 感谢您对帮助我的兴趣。请查看编辑。
  • 现在,请阅读并按照它行事。 :-) 如果您不知道如何操作,请就错误消息提出具体问题
  • 您只需在 ServiceToursClient 构造函数中指定一个端点配置名称。
  • @VladimirGondarev 请问怎么做?

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


【解决方案1】:

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

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

在您的情况下,您那里有多个记录。因此选择适当的并将名称传递给 ServiceToursClient 的构造函数。

new ServiceToursClient("endpointName")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多