Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在MVVM项目中找不到默认终结点_C#_Wpf_Web Services_Mvvm - Fatal编程技术网

C# 在MVVM项目中找不到默认终结点

C# 在MVVM项目中找不到默认终结点,c#,wpf,web-services,mvvm,C#,Wpf,Web Services,Mvvm,我有一个解决方案,其中有一个MVVM项目,它引用了一个WCFWeb服务项目,还有一个WPF项目,它是GUI的一部分 当我在WPF窗口XAML中添加对MVVM主类的引用时,我有一个错误:在客户端ServiceModel的配置部分找不到引用合约“MarketService.IService1”的dafault端点。这可能是由于找不到配置文件,或者在客户端元素中找不到与该端点对应的端点 调用web服务时,MVVM项目中会出现错误: public class MainWindowMVVM { p

我有一个解决方案,其中有一个MVVM项目,它引用了一个WCFWeb服务项目,还有一个WPF项目,它是GUI的一部分

当我在WPF窗口XAML中添加对MVVM主类的引用时,我有一个错误:在客户端ServiceModel的配置部分找不到引用合约“MarketService.IService1”的dafault端点。这可能是由于找不到配置文件,或者在客户端元素中找不到与该端点对应的端点

调用web服务时,MVVM项目中会出现错误:

public class MainWindowMVVM
{
    private IList<Magasin> _Magasins = new ObservableCollection<Magasin>();
    public IList<Magasin> Magasins {
        set
        {
            _Magasins = value;
        }

        get
        {
            return _Magasins;
        }
    }

    public MainWindowMVVM()
    {

        //au démarrage, magasins est remplie grâce à un appel au service
        using (var market = new MarketService.Service1Client())    <---- here is the error
        {
            Supermarche retour = market.GetSupermarche();
            //copier retour.magasins dans magasins
            foreach (Magasin mg in retour.Magasins)
            {
                Magasins.Add(mg);


            }

        }

        //trvMarket.ItemsSource = Magasins;

    }
}
公共类MainWindowMVVM
{
私有IList_Magasins=新的可观测集合();
公共图书馆{
设置
{
_Magasins=价值;
}
得到
{
返回马加辛;
}
}
公共主窗口MVVM()
{
//婚姻、婚姻和服务

使用(var market=new MarketService.Service1Client())您应该将配置添加到正在运行的exectable的
App.config
文件中,即WPF应用程序项目中的文件

未使用引用的类库项目中的
App.config
文件

您还可以通过编程方式创建绑定:

var binding = new System.ServiceModel.BasicHttpBinding();
var endpoint = new EndpointAddress("http://localhost/market11/Service1.svc");

var factory = new ChannelFactory<IService1>(binding, endpoint);

var channel = factory.CreateChannel();
var retour = channel.GetSupermarche();
var binding=new System.ServiceModel.BasicHttpBinding();
var endpoint=新的端点地址(“http://localhost/market11/Service1.svc");
var factory=新的ChannelFactory(绑定,端点);
var channel=factory.CreateChannel();
var retour=channel.getsupermarch();

我已将标记及其子项添加到WPF的app.config中,但即使在重新生成解决方案时,我仍然存在错误。但我可以运行WPF项目…我什么都不懂。我是否也必须向WPF项目添加服务引用?@lolveley:尝试显式定义绑定。请参阅我更新的答案。该应用程序可以运行,没有exp合法绑定,但错误仍然在这里!它编译、运行。谢谢。@lolveley:“它工作”或“错误仍然在那里”?是哪一个?两者都有!xaml标记带下划线,因此错误在这里,但当我运行项目时,它工作了
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/market11/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="MarketService.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>
var binding = new System.ServiceModel.BasicHttpBinding();
var endpoint = new EndpointAddress("http://localhost/market11/Service1.svc");

var factory = new ChannelFactory<IService1>(binding, endpoint);

var channel = factory.CreateChannel();
var retour = channel.GetSupermarche();