代码之家  ›  专栏  ›  技术社区  ›  NotDan

WCF错误-找不到引用协定“UserService”的默认终结点元素。用户服务'

  •  98
  • NotDan  · 技术社区  · 17 年前

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

    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>
    

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

    13 回复  |  直到 12 年前
        1
  •  186
  •   casperOne    14 年前

    解决方案很简单。将类库的配置文件(例如ServiceReferences.ClientConfig)中的端点定义复制到silverlight应用程序的配置文件中。我知道你会希望它不必这样做就能工作,但显然雷德蒙德有人那天度假了。

        2
  •  45
  •   Shimmy Weitzhandler 500 - Internal Server Error    10 年前

    简单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);
    
        3
  •  12
  •   Shimmy Weitzhandler 500 - Internal Server Error    10 年前

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

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

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

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

    对于WPF应用程序,这意味着从 app.config app.config

        4
  •  6
  •   Dale C    12 年前

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

    1. 右键单击并选择更新服务参考
        5
  •  4
  •   Sarav Sarav    16 年前

        6
  •  3
  •   ssilas    15 年前

    将svcutil.exe生成的output.config重命名为app.config。

        7
  •  2
  •   Nick Josevski    17 年前

    你有你的“UserService”类实现的接口吗。

    你的端点应该为合约属性指定一个接口:

    contract="UserService.IUserService"
    
        8
  •  1
  •   david valentine    17 年前

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

        9
  •  1
  •   marc_s MisterSmith    17 年前

    不确定这是否真的是一个问题,但我看到您的绑定配置()有相同的名称。

    马克

        10
  •  0
  •   Jackstine    10 年前

    必须在调用App.config文件中添加服务才能使其正常工作。请确保您最终还是这样做了。这似乎对我有效。

        11
  •  0
  •   Shimmy Weitzhandler 500 - Internal Server Error    10 年前

    当您通过其他应用程序使用您的服务时,会出现此问题。若应用程序有配置文件,只需将您的服务配置信息添加到此文件中即可。 在我的情况下,没有任何配置文件,所以我使用了这种技术,效果很好。只需将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);
    
        12
  •  0
  •   Boody    9 年前

    对于那些与 C “找不到默认终结点” …或者 ... 在定义服务客户端之前,返回visual studio(c#)项目并添加以下行,然后部署项目并重新启动AX客户端,然后重试: 注意,该示例用于 ,您可以根据需要轻松使用任何其他适配器。

     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);
    
        13
  •  -2
  •   VRK    13 年前

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

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

    推荐文章