簡體   English   中英

在WP8上使用WCF進行LINQ to SQL時,出現“ System.InvalidOperationException”

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

這是發生異常的代碼:

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上遵循了本教程

因此,最終的服務參考URL為:http:// IP /WcfTours/ServiceTours.svc。 //99.99.99代表IP

domain publicprivate允許Allow an app through Windows Firewall World Wide Web Services (HTTP)

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 {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(字符串端點配置名稱,EndpointAddress remoteAddress) 1.CreateSimplexFactory() at System.ServiceModel.ClientBase 1處1.CreateSimplexFactory() at System.ServiceModel.ClientBase CreateSimplexFactory 1.CreateSimplexFactory() at System.ServiceModel.ClientBase1..ctor() at PhoneApp1.ServiceTours.ServiceToursClient..ctor() at PhoneApp1.Listado.ListadoWebService() at PhoneApp1.Listado..ctor()} 1 endpointTrait) at System.ServiceModel.ClientBase 1.InitializeChannelFactoryRef()的System.ServiceModel.ClientBase的CreateChannelFactoryRef(EndpointTrait 1 endpointTrait) at System.ServiceModel.ClientBase 1..ctor() at PhoneApp1.ServiceTours.ServiceToursClient..ctor() at PhoneApp1.Listado.ListadoWebService() at PhoneApp1.Listado..ctor()}

在項目中添加Web Service引用后,就會在項目的根文件夾中創建一個新的ServiceReferences.ClientConfig文件。 在某個地方打開它並尋找:

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

就您而言,那里有多個記錄。 因此,請選擇適當的名稱並將其傳遞給ServiceToursClient的構造函數。

new ServiceToursClient("endpointName")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM