简体   繁体   English

使用网络中托管的WCF服务抛出TimeoutException

[英]TimeoutException thrown consuming WCF Service hosted in the Network

I'm writing a web application that will be hosted in Electron on a Raspberry PI. 我正在编写一个Web应用程序,它将在Raspberry PI上的Electron中托管。 The Raspberry PI has a fingerprint scanner attached which returns me a string that I need to check if the fingerprint is registered in my Database on another server. Raspberry PI附带了一个指纹扫描器,它返回一个字符串,我需要检查指纹是否在另一台服务器上的数据库中注册。 I'm doing this by invoking a WCF Service Method hosted on the network. 我这样做是通过调用网络上托管的WCF服务方法来实现的。
Now the problem is when calling the WCF Service I get a timeout after 1 Minute (default timeout) but it works when I'm running the application on my local machine. 现在问题是在调用WCF服务时我在1分钟(默认超时)后得到超时,但是当我在本地计算机上运行应用程序时它会起作用。

Service Code: 服务代码:

[ServiceContract(Namespace = "http://192.168.0.154:8733/GlauxSoft.SnackBox.WebService/")]
public interface IService
{
        [OperationContract]
        Fingerprint GetFingerprintByUniqueId(string uniqueId);
}

public class Service : IService
{
    public Fingerprint GetFingerprintByUniqueId(string uniqueId)
    {
        // This is just a DataBase call, nothing extraordinarily expensive
        using (EvidenceSessionHelper.CreateDefaultWebServiceSession())
        {
            return Fingerprint.MapAuthentifizierungToWebServiceFingerprint(QueryAuthentifizierung.GetFingerprintByUniqueId(uniqueId));
        }
    }
}

Consumer Code: 消费者代码:

[ServiceContract(Namespace = "http://192.168.0.154:8733/GlauxSoft.SnackBox.WebService/", ConfigurationName = "ISnackBoxService")]
public interface ISnackBoxService
{
    [OperationContract(
        Action ="http://192.168.0.154:8733/GlauxSoft.SnackBox.WebService/IService/GetFingerprintByUniqueId", 
        ReplyAction = "http://192.168.0.154:8733/GlauxSoft.SnackBox.WebService/IService/GetFingerprintByUniqueIdResponse")]
    Fingerprint GetFingerprintByUniqueId(string uniqueId);
}

public class ServiceClient : ClientBase<IService>, IService
{
    public SnackBoxServiceClient() : 
            base(GetDefaultBinding(), GetDefaultEndpointAddress())
    {
        Endpoint.Name = EndpointConfiguration.BasicHttpBinding_ISnackBoxService.ToString();
    }

    public enum EndpointConfiguration
    {
        BasicHttpBinding_ISnackBoxService
    }

    public Fingerprint GetFingerprintByUniqueId(string uniqueId)
    {
        return Channel.GetFingerprintByUniqueId(uniqueId);
    }
}

The consumer is a ASP.NET Razor app written in .NET Core 3 Preview 5 使用者是使用.NET Core 3 Preview 5编写的ASP.NET Razor应用程序

And I'm calling the Consumer code like so: 而我正在调用Consumer代码:

var service = new ServiceClient();
var evdFingerprint = service.GetFingerprintByUniqueId("Test String"); // <-- Runs for 1 minute and throws the TimeoutException

Here is the stack trace: 这是堆栈跟踪:

System.TimeoutException: The request channel timed out attempting to send after 00:01:00. System.TimeoutException:请求通道在00:01:00之后尝试发送超时。 Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. 增加传递给Request的调用的超时值或增加Binding上的SendTimeout值。 The time allotted to this operation may have been a portion of a longer timeout. 分配给此操作的时间可能是较长超时的一部分。 ---> System.TimeoutException: The HTTP request to ' http://192.168.0.154:8733/GlauxSoft.SnackBox.WebService/ ' has exceeded the allotted timeout of 00:01:00. ---> System.TimeoutException:对' http://192.168.0.154:8733/GlauxSoft.SnackBox.WebService/ '的HTTP请求超过了分配的超时00:01:00。 The time allotted to this operation may have been a portion of a longer timeout. 分配给此操作的时间可能是较长超时的一部分。 at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.SendRequestAsync(Message message, TimeoutHelper timeoutHelper) at System.ServiceModel.Channels.RequestChannel.RequestAsync(Message message, TimeSpan timeout) System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.SendRequestAsync(Message message,TimeoutHelper timeoutHelper)at System.ServiceModel.Channels.RequestChannel.RequestAsync(Message message,TimeSpan timeout)

Edit: I've done some further testing, it seems like any HTTP request to my local machine isn't getting through as doing wget 192.168.0.154:5106 -o index.html and monitoring my network traffic with wireshark isn't showing me any GET requests to my pc and going to https://192.168.0.154:5106 times out as well. 编辑:我已经做了一些进一步的测试,似乎对我的本地机器的任何HTTP请求都没有通过wget 192.168.0.154:5106 -o index.html并且使用wireshark监控我的网络流量没有显示我任何GET请求到我的电脑,并转到https://192.168.0.154:5106也是。
I am however able to ping my local pc and I can even SSH into my Raspberry PI and I can also establish a VNC Remote Desktop session with my Raspberry PI 然而,我能够ping我的本地电脑,我甚至可以通过SSH连接到我的Raspberry PI,我也可以使用我的Raspberry PI建立VNC远程桌面会话

you can configure time out in many ways on your binding .In Code, 您可以在绑定上以多种方式配置超时。在代码中,

    WSHttpBinding binding = new WSHttpBinding();
    binding.OpenTimeout = new TimeSpan(0, 10, 0);
    binding.CloseTimeout = new TimeSpan(0, 10, 0);
    binding.SendTimeout = new TimeSpan(0, 10, 0);
    binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

or in web.config 或者在web.config中

<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding openTimeout="00:10:00" 
                 closeTimeout="00:10:00" 
                 sendTimeout="00:10:00" 
                 receiveTimeout="00:10:00">
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

GetDefaultBinding(), GetDefaultEndpointAddress() GetDefaultBinding(),GetDefaultEndpointAddress()

I would like that you could share more details related to above method body with me. 我希望你能与我分享更多与上述方法体相关的细节。
What is the ClientCredentailType of the default binding? 什么是默认绑定的ClientCredentailType? since some bindings are not well compatible with Core(WS-* binding). 因为一些绑定与Core(WS- *绑定)不兼容。 Also, have you modified the service endpoint address on the client side when you call the service from another machine? 另外,当您从另一台计算机调用服务时,是否修改了客户端的服务端点地址?
In my opinion, we could use the Microsoft WCF Web Service Reference Provider tool to generate the client proxy, then modify the service endpoint address and provide a client credential explicitly depending on the binding configuration on the server side. 在我看来,我们可以使用Microsoft WCF Web服务引用提供程序工具生成客户端代理,然后根据服务器端的绑定配置修改服务端点地址并显式提供客户端凭据。
Feel free to let me know if the problem still exists. 如果问题仍然存在,请随时告诉我。

修复很简单,我需要使用HTTPS,所以不需要连接到http://192.168.0.154:8733/...我需要连接到https://192.168.0.154:8733/...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM