C# WCF 错误 - 找不到引用合同“UserService.UserService”的默认端点元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/699644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'
提问by NotDan
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. 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.
在 ServiceModel 客户端配置部分中找不到引用合同“UserService.UserService”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。
Resolved!
解决!
I didn't mention that this was a Silverlight application. I had the wcf reference in a DLL which had it's own "ServiceReferences.ClientConfig" file. I moved the contents of the DLL's ServiceReferences.ClientConfig to the main silverlight project and it worked.
我没有提到这是一个 Silverlight 应用程序。我在一个 DLL 中有 wcf 引用,它有自己的“ServiceReferences.ClientConfig”文件。我将 DLL 的 ServiceReferences.ClientConfig 的内容移到了主要的 Silverlight 项目中并且它起作用了。
采纳答案by sprite
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 (e.g. ServiceReferences.ClientConfig) of the class library to the config file of the silverlight application. I know you'd expect it to work without having to do this, but apparently someone in Redmond had a vacation that day.
解决方法很简单。将端点定义从类库的配置文件(例如 ServiceReferences.ClientConfig)复制到 Silverlight 应用程序的配置文件。我知道您希望它无需这样做就可以工作,但显然雷德蒙德的某个人那天有假期。
回答by Nick Josevski
Do you have an Interface that your "UserService" class implements.
你有一个你的“UserService”类实现的接口。
Your endpoints should specify an interface for the contract attribute:
您的端点应该为合同属性指定一个接口:
contract="UserService.IUserService"
回答by david valentine
Not sure if this is an issue. Endpoint and binding both have the same name
不确定这是否是一个问题。端点和绑定都具有相同的名称
回答by marc_s
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", e.g. "UserServiceDefaultBinding", to avoid any potential name clashes.
我通常尝试将我的端点称为“UserServiceBasicHttp”或类似的东西(“绑定”在这里真的没有任何关系),并且我尝试使用“....Configuration”来调用我的绑定配置,例如“UserServiceDefaultBinding”,以避免任何潜在的名称冲突。
Marc
马克
回答by marc_s
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. Then it will work fine.
将 WCF 服务的 web.config 更改为 "endpoint address="" binding="basicHttpBinding"..."(以前为 binding="wsHttpBinding")构建应用程序后,在 "ServiceReferences.ClientConfig" ""configuration> 中具有值. 然后它会正常工作。
回答by Mike Gledhill
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. When my code was in the "main" WPF Application solution, no problem, it worked perfectly. But when I moved the code to the more sensible DAL-layer solution, it would throw the exception.
连接到 Web 服务时出现此错误。当我的代码在“主”WPF 应用程序解决方案中时,没问题,它运行良好。但是当我将代码移到更合理的 DAL 层解决方案时,它会抛出异常。
Could not find default endpoint element that references contract 'MyWebService.MyServiceSoap' in the ServiceModel client configuration section. 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.
在 ServiceModel 客户端配置部分中找不到引用合同“MyWebService.MyServiceSoap”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。
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.configin my DAL solution to the app.configin the main WPF Application solution.
对于WPF应用程序,这意味着复从标签的app.config在我DAL解决的app.config主WPF应用程序的解决方案。
回答by ssilas
Rename the output.config produced by svcutil.exe to app.config. it worked for me.
将 svcutil.exe 生成的 output.config 重命名为 app.config。它对我有用。
回答by VRK
In case if you are using WPF application using PRISM framework then configuration should exist in your start up project (i.e. 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.
简而言之,只需将其从类库中删除并放入启动项目中即可。
回答by Vishal
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);
回答by Dale C
I ran into the same issue, for whatever reason Visual Studio did not update the web config when I first added the service. I found that updating the Service Reference also fixed this issue.
我遇到了同样的问题,无论出于何种原因,Visual Studio 在我第一次添加服务时都没有更新 Web 配置。我发现更新服务参考也解决了这个问题。
Steps:
脚步:
- Navigate to the Service Reference Folder
- Expand it
- Right Click and Select update Service Reference
- Observe web Config be updated
- 导航到服务参考文件夹
- 展开
- 右键单击并选择更新服务参考
- 观察 Web Config 是否更新