WCF错误 - 找不到引用合同'UserService.UserService“默认的终结点元素找不到、元素、错误、合同

2023-09-02 10:24:24 作者:我总是失去不该失去的,得到不该得到的。最后,什么都没有留下。

任何想法如何解决这一问题?

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>

找不到了ServiceModel客户端配置节中引用合同'UserService.UserService默认终结点元素。这可能是因为没有配置文件找到您的应用程序,或者是因为没有终点的元素匹配这份合同可以在客户端元素中找到。

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.

解决!

我没有提到这是一个Silverlight应用程序。我曾在一个DLL有它自己的ServiceReferences.ClientConfig文件中的WCF参考。我搬到了DLL的ServiceReferences.ClientConfig的内容主要Silverlight项目和它的工作。

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应用程序和服务正在从一个类库与正在于它使用的自定义用户控件调用。

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.

解决的办法很简单。从类库的配置文件(如ServiceReferences.ClientConfig)端点定义复制到Silverlight应用程序的配置文件。我知道你希望它无需做这个工作,但显然有人在微软有一个休假的那一天。

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.