Home > Blockchain >  WCF this could be due to the service endpoint binding not using the http protocol, only internet
WCF this could be due to the service endpoint binding not using the http protocol, only internet

Time:09-17

I've a service deployed in my server, self-hosted application using a WCF service. My application serves as a bridge between the database and the front-end application, both applications are WPF. It has been working fine for years, I've been upgrading the "bridge" application and the front end applications without any issues except of course, connection ones.

Currently I'm using HTTP basic binding to communicate between them, no issues, however some time ago I was using TCP because it's faster and it suddenly stopped working, could never find the real reason so I just switched to HTTP, after all this protocol doesn't require me to ping occasionally to keep alive the connection, even though it's slower it's more convenient.

Recently, some days ago I could no longer communicate between applications anymore, internet communication doesn't work anymore it sends "no HTTP response" error but I've had no issues with intranet connections, I can still do it without any issues, it's only internet connection when it fails.

  1. I've not updated either applications recently.

  2. Code works fine in intranet

Which leads me to believe that I indeed am doing it right, therefore I ran a series of tests to figure out what the problem is, all unfruitful:

  1. Disabled firewall

  2. I've several backups, I used some previous instances, still not working

  3. Stopped other services

  4. Changed some configuration parameters in config File

  5. I tried to make a sample service to host it in server but latest VS2019 doesn't include the system.servicemodel DLL in reference (Microsoft fix your crap), instead of trying to fix this I just moved forward to fix my current issue

  6. Changed ports

  7. Restarted server several times.

  8. Restarted both applications several times.

Here's the trace:

server stack trace: en System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) en System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) en System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) en System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) en System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) en System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) en System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: en System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) en System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) en IConexion.Ping() en ConexionClient.Ping()

Inner Exception: Se ha terminado la conexión: Error inesperado de recepción. en System.Net.HttpWebRequest.GetResponse() en System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

Inner Exception: No se puede escribir datos de en la conexión de transporte: Se ha forzado la interrupción de una conexión existente por el host remoto. en System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) en System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) en System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)

Inner Exception: Se ha forzado la interrupción de una conexión existente por el host remoto en System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) en System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

I'm using the WCFtestClient, sometimes it adds the service sometimes it doesn't: When it does it gets all metadata but nothing works, sends that trace, I've even some methods (PING() which returns nothing, it was used to keep connection alive and another one that returns the months of the year, doesn't work either.

I've some websites hosted in the server, can access without any issues from intranet and internet, these website use this "bridge" to retrieve data from the database, therefore it's working fine locally, as well.

I also used the tracelog: couldn't post all the code but it says I/O application error

Can anyone help me figure out what the heck is going on? Right now, I'm going to use my PC to host it and access from another computer, maybe there's something wrong with the server (I don't have an UPS and there was some current cuts lately due to rain), maybe it got corrupted somehow, but my last resort is reinstalling windows server. Thanks!

EDIT: I ran the instance in different machine, same issue... I don't know what is going on.

EDIT 2: Here's the config file code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>

        <services>
            <service name="BSUITE_CONSOLA.Conexion">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
                    contract="BSUITE_CONSOLA.IConexion" />
                <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
                    contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:80/BDB/"/>
                    </baseAddresses>
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                    <useRequestHeadersForMetadataAddress />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <netTcpBinding>
                <binding name="tcp_Unsecured" >
                    <reliableSession enabled="true" />
                    <security mode="None"></security>
                </binding>
            </netTcpBinding>
    </bindings>
    </system.serviceModel>
</configuration>

EDIT 3: I know using sockets is harder to program but do you think it's less faulty alike? i'm sick of WCF failing so much randomly

EDIT 4: I've tried hosting in different computer, using different ports, using different protocol (TCP, NETTCP, NETHTPS). Currently im using Visual studio to host the app and debug using the WCFtestclient on another network to connect, it only gets the metadata but it can't retrieve the any method when called

CodePudding user response:

If I understand you correctly, you can try the following steps:

  1. You say that this problem exists on other machines, but on the premise that the network of that machine is ok, it means that there is a problem with the code.
  2. Switch to TCP and try again. If it works, the HTTP response is the reason.

You can also check out the links below:WCF service not working when accessed over HTTPS and HTTP.

Thanks.

CodePudding user response:

I cannot begin to express how frustrated i felt over the last 4 days. Turns out it wasn't anything i was doing. Yesterday i did some config changes and i thought it was because of that but today i reverted back to previous setting and guess what? it worked. There were several ISP guys fixing some nodes all around in a 5km radius. I think it was indeed my ISP that caused this, how? i have no idea since i explained i could access IIS hosted webpages but not this service using the 80 port. I just want to punch them in the face really hard, sadly that's illegal.

  • Related