0

这是发生异常的代码:

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

World Wide Web Services (HTTP)inAllow an app through Windows Firewall允许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(String endpointConfigurationName, EndpointAddress remoteAddress) 在 System.ServiceModel.EndpointTrait 1.CreateChannelFactoryRef 1.CreateSimplexFactory() at System.ServiceModel.ClientBase(EndpointTrait 1 endpointTrait) at System.ServiceModel.ClientBase1.InitializeChannelFactoryRef() 在 System.ServiceModel.ClientBase1..ctor() at PhoneApp1.ServiceTours.ServiceToursClient..ctor() at PhoneApp1.Listado.ListadoWebService() at PhoneApp1.Listado..ctor()}

4

1 回答 1

1

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

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

在你的情况下,你有不止一个记录。因此选择适当的并将名称传递给 ServiceToursClient 的构造函数。

new ServiceToursClient("endpointName")
于 2013-10-15T11:46:25.350 回答