.net Can';t从WPF应用程序访问WCF websocket服务
我正试图通过WebSocket使用一个简单的WCF服务(netHttpBinding with.net Can';t从WPF应用程序访问WCF websocket服务,.net,wpf,wcf,websocket,wcf-binding,.net,Wpf,Wcf,Websocket,Wcf Binding,我正试图通过WebSocket使用一个简单的WCF服务(netHttpBinding withtransportUsage=“Always”) 从控制台应用程序使用服务时,它工作正常,但从WPF应用程序使用服务时,会引发超时错误: <system.serviceModel> <bindings> <netHttpBinding> <binding name="NetHttpBinding_IService1
transportUsage=“Always”
)
从控制台应用程序使用服务时,它工作正常,但从WPF应用程序使用服务时,会引发超时错误:
<system.serviceModel>
<bindings>
<netHttpBinding>
<binding name="NetHttpBinding_IService1">
<webSocketSettings transportUsage="Always" />
</binding>
</netHttpBinding>
</bindings>
<client>
<endpoint address="ws://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
binding="netHttpBinding" bindingConfiguration="NetHttpBinding_IService1"
contract="ServiceReference1.IService1" name="NetHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
此请求操作已发送到
在配置的超时(00:01:00)内未收到答复
从transportUsage=“始终”
切换到transportUsage=“从不”
时没有超时
如何从WPF应用程序访问websocket WCF服务?
服务合同:
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
服务:
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
配置:
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="netHttpBinding" contract="WcfServiceLibrary1.IService1" bindingConfiguration="My_NetHttpBindingConfig">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netHttpBinding>
<binding name="My_NetHttpBindingConfig">
<webSocketSettings transportUsage="Always"/>
</binding>
</netHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
WPF代码(不工作):
WPF和控制台应用程序的配置相同:
<system.serviceModel>
<bindings>
<netHttpBinding>
<binding name="NetHttpBinding_IService1">
<webSocketSettings transportUsage="Always" />
</binding>
</netHttpBinding>
</bindings>
<client>
<endpoint address="ws://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
binding="netHttpBinding" bindingConfiguration="NetHttpBinding_IService1"
contract="ServiceReference1.IService1" name="NetHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
我刚刚在另一个论坛上收到了答案:这是主UI通道上的死锁 详细说明和解决方法可在此处找到:
<system.serviceModel>
<bindings>
<netHttpBinding>
<binding name="NetHttpBinding_IService1">
<webSocketSettings transportUsage="Always" />
</binding>
</netHttpBinding>
</bindings>
<client>
<endpoint address="ws://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
binding="netHttpBinding" bindingConfiguration="NetHttpBinding_IService1"
contract="ServiceReference1.IService1" name="NetHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>