可能重复:
WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'WCF:找不到默认的终结点元素引用合同
我的客户端代码如下:
public virtual bool CanExecute(Move movement)
{
using (MediatorServiceContractClient mediatorProxy = new MediatorServiceContractClient())
{
return mediatorProxy.CanMove(movement);
}
}
出现的错误在MediatorServiceContractClient的构造函数中。
该合同是如下:
namespace GameServices
{
[ServiceContract]
public interface IMediatorServiceContract
{
[OperationContract]
bool CanMove(Move move);
}
}
我有具有以下配置数据一个GameServices库:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMediatorServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/GameServices/Mediator/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMediatorServiceContract"
contract="GameViewModel.MediatorServiceReference.IMediatorServiceContract"
name="WSHttpBinding_IMediatorServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="GameServices.MediatorService">
<endpoint address="" binding="wsHttpBinding" contract="GameServices.IMediatorServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/GameServices/Mediator/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我然后有一个具有以下配置的数据的视图模型库:
enter code here`<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMediatorServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/GameServices/Mediator/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMediatorServiceContract2"
contract="GameViewModel.MediatorServiceReference.IMediatorServiceContract"
name="WSHttpBinding_IMediatorServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
我还在运行时收到以下错误消息: 找不到在ServiceModel客户端配置部分中引用合同“MediatorServiceReference.IMediatorServiceContract”的默认端点元素。这可能是因为没有找到适用于您的应用程序的配置文件,或者因为在客户端元素中找不到匹配此合同的端点元素。
我查看了关于这个常见问题的所有意见和反馈。但对我来说,问题依然存在,我被卡住了。我错过了什么?为什么这很复杂?
发布使用服务(即客户端)的代码。我猜第一个配置文件是用于服务的(但为什么它有一个客户端端点?),第二个用于客户端连接。 –
是的。第一个配置数据是服务器端。配置数据的第二篇文章是客户端。 –
客户端端点是在服务器端配置文件中自动生成的。 –