c# - WCF 错误 - 找不到引用契约(Contract) 'UserService.UserService' 的默认终结点元素

标签 c# .net wcf

有什么办法解决这个问题吗?

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>

在 ServiceModel 客户端配置部分找不到引用契约(Contract)“UserService.UserService”的默认端点元素。这可能是因为没有找到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。

已解决!

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

最佳答案

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

解决方法很简单。将端点定义从类库的配置文件(例如 ServiceReferences.ClientConfig)复制到 silverlight 应用程序的配置文件。我知道您希望它在不必执行此操作的情况下也能正常工作,但显然雷德蒙德的某个人那天正在休假。

关于c# - WCF 错误 - 找不到引用契约(Contract) 'UserService.UserService' 的默认终结点元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/699644/

相关文章:

c# - 将 pb 模型文件加载到 TensorFlowSharp 中

c# - 用于图像和文档的 SQL 列的数据类型

c# - Linq 用表达式查询抽象,哪种方式更好?

wcf - Azure Appfabric 缓存 + WCF Web 服务

c# - 在 cshtml 中为 View 模型呈现编辑器

c# - MVVMCross支持asp.net编程吗?

c# - 从函数返回日期 int 值

C#:在 HttpContextAccessor 中添加自定义属性

c# - 无法让 netTcpBinding 请求显示在 Fiddler 中

c# - 如何保证同一时间只有一个用户可以执行一段代码