简体   繁体   中英

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. 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. I'm doing this by invoking a WCF Service Method hosted on the network.
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.

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

And I'm calling the Consumer code like so:

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. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. 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. 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)

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.
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

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

<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()

I would like that you could share more details related to above method body with me.
What is the ClientCredentailType of the default binding? since some bindings are not well compatible with Core(WS-* binding). 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.
Feel free to let me know if the problem still exists.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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