我创建了一个在IIS 7中托管的WCF服务
我的.NET版本是4.0
我的操作系统是Windows 7旗舰版
我的服务地址:
当我添加服务参考时,我得到两个警告:
首先:
Warning 2 Custom tool warning: Endpoint 'NetTcpBinding_IChat' at address 'net.tcp://localhost:4504/WPFHost/tcp' is not compatible with Silverlight 4. Skipping... D:\Projects\C#\WCF\SilverlightApplication1\SilverlightApplication1\Service References\SV\Reference.svcmap 1 1 SilverlightApplication1
第二
Warning 3 Custom tool warning: No endpoints compatible with Silverlight 4 were found. The generated client class will not be usable unless endpoint information is provided via the constructor. D:\Projects\C#\WCF\SilverlightApplication1\SilverlightApplication1\Service References\SV\Reference.svcmap 1 1 SilverlightApplication1
我的服务Appconfig文件如下所示:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="WCFService.Service"
behaviorConfiguration="behaviorConfig">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:4504/WPFHost/"/>
<add baseAddress="http://localhost:4505/WPFHost/"/>
</baseAddresses>
</host>
<endpoint address="tcp"
binding="netTcpBinding"
bindingConfiguration="tcpBinding"
contract="WCFChatLibrary.IChat"/>
<endpoint address="net.tcp://localhost:4503/WPFHost/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfig">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding"
maxBufferSize="67108864"
maxReceivedMessageSize="67108864"
maxBufferPoolSize="67108864"
transferMode="Buffered"
closeTimeout="00:00:10"
openTimeout="00:00:10"
receiveTimeout="00:20:00"
sendTimeout="00:01:00"
maxConnections="100">
<security mode="None">
</security>
<readerQuotas maxArrayLength="67108864"
maxBytesPerRead="67108864"
maxStringContentLength="67108864"/>
<reliableSession enabled="true" inactivityTimeout="00:20:00"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
当我调用该服务时,它会抛出异常。这是我的代码:
if (this.proxy == null)
{
try
{
this.StatusTxtBlock.Text = "Ready";
this.localClient = new Client();
this.localClient.Username = "User-" + Guid.NewGuid();
this.proxy = new ChatClient(new InstanceContext(this));
this.proxy.OpenAsync();
this.proxy.ConnectAsync(this.localClient);
this.proxy.ConnectCompleted += new EventHandler<ConnectCompletedEventArgs>(proxy_ConnectCompleted);
}
catch (Exception ex)
{
this.StatusTxtBlock.Text = "Exception: "+ ex.Message;
}
}
,例外是:
Exception: The given key was not present in the dictionary
我遵循此tutorial但没有运气
我不知道该怎么做,我的思想和愿景会变得空白,也许我会发疯。请有人救救我(我的意思是帮助我)。
答案 0 :(得分:1)
Silverlight 4支持服务器上的NetTcpBinding
子集。例如,它不支持安全性(这对你的情况很好,因为你的绑定中有<security mode="None">
),它也不支持可靠的消息传递(这可能是你的情况下的问题,因为你在绑定中启用了它。这是netTcpBinding
的一个绑定配置,它与SL兼容:
<bindings>
<netTcpBinding>
<binding name="SLCompatible">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
答案 1 :(得分:0)
此MSDN article表示NetTcpBinding
无法与Silverlight 4一起使用。
我不确定是否相信Tomasz Janczuk或MSDN,但Tomasz的文章是2年,所以我的猜测是:NetTcpBinding
计划用于Silverlight 4,但不包括在最后。
您可以考虑切换到BasicHttpBinding
或'滚动您自己的'自定义绑定,如following article中所述。