我无法让双工 Web 服务正常工作,我收到此错误:
在 ServiceModel 客户端配置部分中找不到引用合同“IService1”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。
这是我的单元测试尝试访问该服务时抛出的。我发现了类似的 SO 问题:
WCF 错误 - 找不到引用合同“UserService.UserService”的默认端点元素
答案是“将配置文件包含到另一个项目中”,但这究竟是什么意思?
- 我是否将服务编译成 DLL 并包含它?
- 我是复制“system.serviceModel”中包含的所有内容还是其中的一个子集?
- 与端点有关吗?
编辑:配置文件
网页配置
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name ="svcbh">
<serviceMetadata httpGetEnabled="False"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
<services>
<service name ="Test_Duplex.Service1" behaviorConfiguration ="svcbh" >
<host>
<baseAddresses>
<add baseAddress = "http://localhost:3857/Service1.svc" />
</baseAddresses>
</host>
<endpoint name ="duplexendpoint"
address =""
binding ="wsDualHttpBinding"
contract ="Test_Duplex.IService1"/>
<endpoint name ="MetaDataTcpEndpoint"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
输出配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="duplexendpoint" 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">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3857/Service1.svc" binding="wsDualHttpBinding"
bindingConfiguration="duplexendpoint" contract="Test_Duplex.IService1"
name="duplexendpoint">
<identity>
<userPrincipalName value="12680@altus.local" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>