![](/img/trans.png)
[英]Cannot add server reference: Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it
[英]Getting an error: Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it
我有一个WCF服务和一个Silverlight 5客户端。 我已经定义了以下接口:
[ServiceContract(Namespace = "Silverlight", CallbackContract = typeof(IDuplexClient))]
public interface IDuplexService
{
[OperationContract]
void Subscribe(string userId);
[OperationContract]
void Unsubscribe(string userId);
}
[ServiceContract]
public interface IDuplexClient
{
[OperationContract(IsOneWay = true)]
void PushNotification(string msg);
}
这是我的Web.config文件:
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
当我尝试运行服务时,我得到:
由于编译期间发生异常,无法激活服务'/ServerService.svc'。 异常消息是:Contract需要Duplex,但Binding'BasicHttpBinding'不支持它,或者没有正确配置以支持它。
我知道我需要为Web.config添加一些属性,但无论我在哪里(以及我尝试过的任何东西)都无法使其工作。
我是WCF的新手,我希望你对这个问题有所帮助。 我所有的谷歌搜索引导我无处可回答在这里问同样问题的人的答案对我不起作用。
所以我决定放弃搜索,然后问。
更新:我使用此链接创建界面 - http://msdn.microsoft.com/en-us/library/cc645027%28v=vs.95%29.aspx
如果这是WCF的web.config配置的范围,那么你就错过了 定义合同的部分:
<services>
<service name="WebApplication1.Service1">
<endpoint address="" binding="wsDualHttpBinding" contract="WebApplication1.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
如果您确实指定了此部分,另一个可能的原因是合同名称不是完全合格的; 它必须包含完整的命名空间,而不仅仅是合同的名称。
以下是完整的System.ServiceModel配置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="WebApplication1.Service1">
<endpoint address="" binding="wsHttpBinding" contract="WebApplication1.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
在这种情况下,应用程序命名空间是WebApplication1,服务的类名是Service1(即Service1.svc),Service1实现的接口是IService1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.