Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Can';t从WPF应用程序访问WCF websocket服务_.net_Wpf_Wcf_Websocket_Wcf Binding - Fatal编程技术网

.net Can';t从WPF应用程序访问WCF websocket服务

.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

我正试图通过WebSocket使用一个简单的WCF服务(netHttpBinding with
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>