可能重複:
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」的默認端點元素。這可能是因爲沒有找到適用於您的應用程序的配置文件,或者因爲在客戶端元素中找不到匹配此合同的端點元素。
我查看了關於這個常見問題的所有意見和反饋。但對我來說,問題依然存在,我被卡住了。我錯過了什麼?爲什麼這很複雜?
發佈使用服務(即客戶端)的代碼。我猜第一個配置文件是用於服務的(但爲什麼它有一個客戶端端點?),第二個用於客戶端連接。 –
是的。第一個配置數據是服務器端。配置數據的第二篇文章是客戶端。 –
客戶端端點是在服務器端配置文件中自動生成的。 –