C# WCF错误-找不到引用协定的默认终结点元素';UserService.UserService';

C# WCF错误-找不到引用协定的默认终结点元素';UserService.UserService';,c#,.net,wcf,C#,.net,Wcf,有没有办法解决这个问题 UserService.UserServiceClient userServiceClient = new UserServiceClient(); userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted); userService

有没有办法解决这个问题

UserService.UserServiceClient userServiceClient = new UserServiceClient();
            userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted);
            userServiceClient.GetUsersAsync(searchString);
UserService.UserServiceClient UserServiceClient=newuserserviceclient();
userServiceClient.GetUsersCompleted+=新事件处理程序(userServiceClient\u GetUsersCompleted);
userServiceClient.GetUsersAsync(searchString);


在ServiceModel客户端配置节中找不到引用约定“UserService.UserService”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的端点元素

决心


我没有提到这是一个Silverlight应用程序。我在一个DLL中有wcf引用,它有自己的“ServiceReferences.ClientConfig”文件。我将DLL的ServiceReferences.ClientConfig的内容移动到主silverlight项目中,它成功了。

您是否有“UserService”类实现的接口

端点应为协定属性指定接口:

contract="UserService.IUserService"

不确定这是否是一个问题。
端点和绑定都具有相同的名称

不确定这是否真的是个问题,但我发现您的绑定配置()具有相同的名称

我通常尝试调用我的端点,比如“UserServiceBasicHttp”或类似的东西(“绑定”在这里真的没有任何作用),我尝试使用“…配置”来调用我的绑定配置,例如“UserServiceDefaultBinding”,以避免任何潜在的名称冲突


Marc

在构建应用程序后,将WCF服务的web.config更改为“endpoint address=”“binding=“basicHttpBinding”…(以前的binding=“wsHttpBinding”),在“servicerences.ClientConfig”“配置”中具有该值。然后它就可以正常工作了。

我也遇到了同样的问题。我的应用程序也是一个Silverlight应用程序,该服务是从一个类库中调用的,该类库中使用了一个自定义UserControl


解决办法很简单。将端点定义从类库的配置文件(例如servicerences.ClientConfig)复制到silverlight应用程序的配置文件。我知道你希望它在不必这样做的情况下工作,但显然那天雷德蒙有人休假。

以防有人在使用WPF(而不是WCF或Silverlight)时遇到同样的问题:

我在连接到Web服务时出现了此错误。当我的代码在“主”WPF应用程序解决方案中时,没问题,它工作得非常好。但是当我将代码移动到更合理的DAL层解决方案时,它会抛出异常

在ServiceModel客户端配置部分中找不到引用约定“MyWebService.MyServiceSoap”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的端点元素

正如本线程中“Sprite”所述,您需要手动复制标记


对于WPF应用程序,这意味着将标记从my DAL解决方案中的app.config复制到主WPF应用程序解决方案中的app.config。

将svcutil.exe生成的output.config重命名为app.config。
它对我很有用。

如果您使用的是使用PRISM框架的WPF应用程序,那么配置应该存在于您的启动项目中(即引导程序所在的项目中)


简而言之,只需将其从类库中删除并放入启动项目中即可

您还可以在类库中以编程方式设置这些值,这将避免配置文件在库中不必要的移动。 简单BasciHttpBinding的示例代码为-

BasicHttpBinding basicHttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
basicHttpbinding.Name = "BasicHttpBinding_YourName";
basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
basicHttpbinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

EndpointAddress endpointAddress = new EndpointAddress("http://<Your machine>/Service1/Service1.svc");
Service1Client proxyClient = new Service1Client(basicHttpbinding,endpointAddress);
BasicHttpBinding BasicHttpBinding=新的BasicHttpBinding(BasicHttpSecurityMode.None);
basicHttpbinding.Name=“basicHttpbinding\u YourName”;
basicHttpbinding.Security.Transport.ClientCredentialType=HttpClientCredentialType.None;
basicHttpbinding.Security.Message.ClientCredentialType=BasicHttpMessageCredentialType.UserName;
EndpointAddress EndpointAddress=新的EndpointAddress(“http:///Service1/Service1.svc");
Service1Client proxyClient=新Service1Client(basicHttpbinding,endpointAddress);

我遇到了同样的问题,无论出于何种原因,当我第一次添加服务时,Visual Studio没有更新web配置。我发现更新服务引用也解决了这个问题

步骤:

  • 导航到服务引用文件夹
  • 扩展它
  • 右键单击并选择更新服务引用
  • 请注意要更新的web配置

  • 当您通过其他应用程序使用服务时会出现此问题。如果应用程序具有配置文件,请将您的服务配置信息添加到此文件中。 在我的情况下,没有任何配置文件,所以我使用了这种技术,效果很好。只需将url地址存储在应用程序中,读取它并使用BasicHttpBinding()方法将其作为参数发送到服务应用程序。这是我如何做的简单演示:

    Configuration config = new Configuration(dataRowSet[0]["ServiceUrl"].ToString());
    
    var remoteAddress = new System.ServiceModel.EndpointAddress(config.Url);
    
    
    SimpleService.PayPointSoapClient client = 
        new SimpleService.PayPointSoapClient(new System.ServiceModel.BasicHttpBinding(), 
        remoteAddress);
    SimpleService.AccountcredResponse response = client.AccountCred(request);
    

    必须在调用App.config文件中添加该服务才能正常工作。确保你终究能做到这一点。这似乎对我有效。

    对于那些使用AX 2012 AIF服务并试图在AX(x++)内调用C#或VB项目并遭受“找不到默认端点”等错误的人,。。。或“未找到合同”
    。。。 返回到VisualStudio(c#)项目,在定义服务客户机之前添加这些行,然后部署t
    Configuration config = new Configuration(dataRowSet[0]["ServiceUrl"].ToString());
    
    var remoteAddress = new System.ServiceModel.EndpointAddress(config.Url);
    
    
    SimpleService.PayPointSoapClient client = 
        new SimpleService.PayPointSoapClient(new System.ServiceModel.BasicHttpBinding(), 
        remoteAddress);
    SimpleService.AccountcredResponse response = client.AccountCred(request);
    
     Uri Address = new Uri("net.tcp://your-server:Port>/DynamicsAx/Services/your-port-name");
     NetTcpBinding Binding = new NetTcpBinding();
     EndpointAddress EndPointAddr = new EndpointAddress(Address);
     SalesOrderServiceClient Client = new SalesOrderServiceClient(Binding, EndPointAddr);