繁体   English   中英

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

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

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

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”的默认端点元素。 这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

解决!

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

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

解决方案很简单。 将端点定义从类库的配置文件(例如ServiceReferences.ClientConfig)复制到silverlight应用程序的配置文件。 我知道你希望它能够在不必这样做的情况下工作,但显然雷蒙德的某个人当天有个假期。

您还可以在类库中以编程方式设置这些值,这样可以避免配置文件在库中不必要地移动。 简单的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);

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

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

无法在ServiceModel客户端配置部分中找到引用合同“MyWebService.MyServiceSoap”的默认端点元素。 这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

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

对于WPF应用程序,这意味着复制从app.config中的标签在我的DAL解决主WPF应用解决方案的app.config。

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

脚步:

  1. 导航到服务参考文件夹
  2. 展开它
  3. 右键单击并选择更新服务参考
  4. 观察Web配置更新

将WCF服务的web.config更改为“endpoint address =”“binding =”basicHttpBinding“...”(先前绑定=“wsHttpBinding”)构建应用程序后,在“ServiceReferences.ClientConfig”中“”配置>具有该值。 然后它会正常工作。

将svcutil.exe生成的output.config重命名为app.config。 它对我有用。

你有一个“UserService”类实现的接口吗?

您的端点应指定contract属性的接口:

contract="UserService.IUserService"

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

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

我通常尝试将我的端点称为“UserServiceBasicHttp”或类似的东西(“Binding”在这里没有任何事情要做),我尝试用“.... Configuration”调用我的绑定配置,例如“UserServiceDefaultBinding”,以避免任何潜在的名称冲突。

当您通过其他应用程序使用您的服务时会出现此问题。如果应用程序有配置文件,只需将您的服务配置信息添加到此文件。 在我的情况下,没有任何配置文件所以我使用这种技术,它工作正常。只需在应用程序中存储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);

必须在调用App.config文件中添加服务才能使其正常工作。 毕竟确保你,但它。 这似乎对我有用。

对于那些使用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);

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

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM