简体   繁体   English

WCF错误 - 找不到引用合同“UserService.UserService”的默认端点元素

[英]WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'

Any ideas how to fix this? 任何想法如何解决这一问题?

UserService.UserServiceClient userServiceClient = new UserServiceClient();
            userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted);
            userServiceClient.GetUsersAsync(searchString);

.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_UserService" 
                     maxBufferSize="2147483647" 
                     maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:52185/UserService.svc" 
                  binding="basicHttpBinding" 
                  bindingConfiguration="BasicHttpBinding_UserService" 
                  contract="UserService.UserService"
                  name="BasicHttpBinding_UserService" />
    </client>
    <behaviors>
        <serviceBehaviors>
            <behavior name="Shell.Silverlight.Web.Service3Behavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
        <service behaviorConfiguration="Shell.Silverlight.Web.Service3Behavior" 
                 name="Shell.Silverlight.Web.Service3">
            <endpoint address="" 
                      binding="basicHttpBinding" 
                      contract="Shell.Silverlight.Web.Service3" />
            <endpoint address="mex" 
                      binding="mexHttpBinding" 
                      contract="IMetadataExchange" />
        </service>
    </services>
</system.serviceModel>

Could not find default endpoint element that references contract 'UserService.UserService' in the ServiceModel client configuration section. 无法在ServiceModel客户端配置部分中找到引用合同“UserService.UserService”的默认端点元素。 This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. 这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

Resolved! 解决!

I didn't mention that this was a Silverlight application. 我没有提到这是一个Silverlight应用程序。 I had the wcf reference in a DLL which had it's own "ServiceReferences.ClientConfig" file. 我在DLL中有wcf引用,它有自己的“ServiceReferences.ClientConfig”文件。 I moved the contents of the DLL's ServiceReferences.ClientConfig to the main silverlight project and it worked. 我将DLL的ServiceReferences.ClientConfig的内容移动到主Silverlight项目并且它工作了。

I had a run in with the same problem. 我遇到了同样的问题。 My application was also a Silverlight application and the service was being called from a class library with a custom UserControl that was being used in it. 我的应用程序也是一个Silverlight应用程序,该服务是从类库中调用的,其中包含正在使用的自定义UserControl。

The solution is simple. 解决方案很简单。 Copy the endpoint definitions from the config file (eg ServiceReferences.ClientConfig) of the class library to the config file of the silverlight application. 将端点定义从类库的配置文件(例如ServiceReferences.ClientConfig)复制到silverlight应用程序的配置文件。 I know you'd expect it to work without having to do this, but apparently someone in Redmond had a vacation that day. 我知道你希望它能够在不必这样做的情况下工作,但显然雷蒙德的某个人当天有个假期。

You can also set these values programatically in the class library, this will avoid unnecessary movement of the config files across the library. 您还可以在类库中以编程方式设置这些值,这样可以避免配置文件在库中不必要地移动。 The example code for simple BasciHttpBinding is - 简单的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);

Just in case anyone hits the same problem whilst using WPF (rather than WCF or Silverlight): 以防万一在使用WPF(而不是WCF或Silverlight)时遇到同样的问题:

I had this error, when connecting to a Web Service. 连接到Web服务时出现此错误。 When my code was in the "main" WPF Application solution, no problem, it worked perfectly. 当我的代码在“主要”WPF应用程序解决方案中,没有问题,它完美地工作。 But when I moved the code to the more sensible DAL-layer solution, it would throw the exception. 但是当我将代码移动到更合理的DAL层解决方案时,它会抛出异常。

Could not find default endpoint element that references contract 'MyWebService.MyServiceSoap' in the ServiceModel client configuration section. 无法在ServiceModel客户端配置部分中找到引用合同“MyWebService.MyServiceSoap”的默认端点元素。 This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. 这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

As has been stated by "Sprite" in this thread, you need to manually copy the tag. 正如此线程中“Sprite”所述,您需要手动复制标记。

For WPF apps, this means copying the tag from the app.config in my DAL solution to the app.config in the main WPF Application solution. 对于WPF应用程序,这意味着复制从app.config中的标签在我的DAL解决主WPF应用解决方案的app.config。

I ran into the same issue, for whatever reason Visual Studio did not update the web config when I first added the service. 我遇到了同样的问题,无论出于什么原因,当我第一次添加服务时,Visual Studio没有更新Web配置。 I found that updating the Service Reference also fixed this issue. 我发现更新服务参考也解决了这个问题。

Steps: 脚步:

  1. Navigate to the Service Reference Folder 导航到服务参考文件夹
  2. Expand it 展开它
  3. Right Click and Select update Service Reference 右键单击并选择更新服务参考
  4. Observe web Config be updated 观察Web配置更新

Change the web.config of WCF service as "endpoint address="" binding="basicHttpBinding"..." (previously binding="wsHttpBinding")After build the app, in "ServiceReferences.ClientConfig" ""configuration> has the value. 将WCF服务的web.config更改为“endpoint address =”“binding =”basicHttpBinding“...”(先前绑定=“wsHttpBinding”)构建应用程序后,在“ServiceReferences.ClientConfig”中“”配置>具有该值。 Then it will work fine. 然后它会正常工作。

Rename the output.config produced by svcutil.exe to app.config. 将svcutil.exe生成的output.config重命名为app.config。 it worked for me. 它对我有用。

Do you have an Interface that your "UserService" class implements. 你有一个“UserService”类实现的接口吗?

Your endpoints should specify an interface for the contract attribute: 您的端点应指定contract属性的接口:

contract="UserService.IUserService"

Not sure if this is an issue. 不确定这是否是一个问题。 Endpoint and binding both have the same name 端点和绑定都具有相同的名称

Not sure if it's really a problem, but I see you have the same name for your binding configuration (). 不确定它是否真的有问题,但我看到你的绑定配置名称相同()。

I usually try to call my endpoints something like "UserServiceBasicHttp" or something similar (the "Binding" really doesn't have anything to do here), and I try to call my binding configurations something with "....Configuration", eg "UserServiceDefaultBinding", to avoid any potential name clashes. 我通常尝试将我的端点称为“UserServiceBasicHttp”或类似的东西(“Binding”在这里没有任何事情要做),我尝试用“.... Configuration”调用我的绑定配置,例如“UserServiceDefaultBinding”,以避免任何潜在的名称冲突。

Marc

This problem occures when you use your service via other application.If application has config file just add your service config information to this file. 当您通过其他应用程序使用您的服务时会出现此问题。如果应用程序有配置文件,只需将您的服务配置信息添加到此文件。 In my situation there wasn't any config file so I use this technique and it worked fine.Just store url address in application,read it and using BasicHttpBinding() method send it to service application as parameter.This is simple demonstration how I did it: 在我的情况下,没有任何配置文件所以我使用这种技术,它工作正常。只需在应用程序中存储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);

Had to add the service in the calling App.config file to have it work. 必须在调用App.config文件中添加服务才能使其正常工作。 Make sure that you but it after all . 毕竟确保你,但它。 This seemed to work for me. 这似乎对我有用。

For those who work with AX 2012 AIF services and try to call there C# or VB project inside AX (x++) and suffer from such errors of "could not find default endpoint" ... or "no contract found" ... go back to your visual studio (c#) project and add these lines before defining your service client, then deploy the project and restart AX client and retry: Note, the example is for NetTcp adapter , you could easily use any other adapter instead according to your need. 对于那些使用AX 2012 AIF服务并尝试在AX(x ++)内调用C#或VB项目并遭受“无法找到默认端点”的错误 ......或“找不到合同”的人 ...返回到您的visual studio(c#)项目并在定义服务客户端之前添加这些行,然后部署项目并重新启动AX客户端并重试:注意,该示例适用于NetTcp适配器 ,您可以根据需要轻松使用任何其他适配器。

 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);

In case if you are using WPF application using PRISM framework then configuration should exist in your start up project (ie in the project where your bootstrapper resides.) 如果您使用PRISM框架使用WPF应用程序,则配置应该存在于您的启动项目中(即在您的引导程序所在的项目中)。

In short just remove it from the class library and put into a start up project. 简而言之,只需将其从类库中删除并放入启动项目即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF错误 - 找不到引用合同的默认端点元素 - WCF Error - Could not find default endpoint element that references contract 找不到引用合同的默认端点元素 - 托管wcf - Could not find default endpoint element that references contract - Hosting wcf 在WCF中找不到引用合同的默认终结点元素 - Could not find default endpoint element that references contract in WCF WCF 安装程序 class - 找不到引用合同的默认端点元素 - WCF installer class - Could not find default endpoint element that references contract 在 SQL 中创建一个调用 WCF 服务器的 DLL 错误:找不到引用合同的默认端点元素 - Making a DLL in SQL which call WCF Server Error : Could not find default endpoint element that references contract 找不到引用合同的默认端点元素 - Could not find default endpoint element that references contract 找不到引用合同的默认端点元素 - Could not find default endpoint element that references contract 找不到引用合同的默认端点元素 - Could not find default endpoint element that references contract 找不到引用合同的默认端点元素 - Could not find default endpoint element that references contract 找不到引用合同的默认端点元素? - Could not find default endpoint element that references contract?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM