Ошибка requested service not found

I have a windows service application which works using remoting. It is used to display baloon tip. However, it sometimes throws this error:

Exception :Requested Service not found
Inner Exception : Stack Trace : Server stack trace: at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Baloontip.clsBaloonTool.Messagebox(String Message)

Can any body please help me with this issue.

Patrick McDonald's user avatar

asked Apr 16, 2010 at 9:24

mathirengasamy's user avatar

1

If the error occurs after some time, it is possible that you doesn´t override the InitializeLifetimeService method of the base class MarshalByRefObject.

By default, if you doesn´t override the method, the remote object is destroyed after some time (I think 5 minutes). If you override the method and return null, the object has an endless life time.

public override object InitializeLifetimeService() {
  return null;
}

usr's user avatar

usr

168k35 gold badges239 silver badges369 bronze badges

answered Apr 16, 2010 at 9:29

Jehof's user avatar

JehofJehof

34.5k10 gold badges123 silver badges155 bronze badges

2

I am trying to build a very simple .Net remoting connection and can’t seem to figure out the magic incantation.

I have a server side class that is meant to be a singleton and live for the duration of the service process.

public class MyRemoteServerClass : MarshalByRefObject
{
    public void DoSomething()
    {
        System.Diagnostics.Trace.Assert(false);
    }

    public override object InitializeLifetimeService()
    {
        return null;
    }
}

Based on my readings of .Net remoting, I wrote this code to instantiate and register the server class in the service:

    static void Main(string[] args)
    {
        MyRemoteServerClass server = new MyRemoteServerClass();
        TcpChannel channel = new TcpChannel(8080);
        ChannelServices.RegisterChannel(channel, false);
        string url = "tcp://localhost:8080/MyRemoteServerClass";
        RemotingServices.Marshal(server, url, server.GetType());
        System.Console.ReadLine();
    }

I wrote this code in the .Net winforms client to invoke the ‘MyRemoteServerClass.DoSomething’ function:

    private void button1_Click(object sender, EventArgs e)
    {
        string url = "tcp://localhost:8080/MyRemoteServerClass";
        ChannelServices.RegisterChannel(new TcpChannel(), false);
        MyRemoteServerClass root = Activator.GetObject(typeof(MyRemoteServerClass), url) as MyRemoteServerClass;
        root.DoSomething();
    }

The ‘Activate.GetObject’ call appears to get a proxy reference to the server ‘MyRemoteServerClass’ instance. However, when I call ‘DoSomething’ I get a «Requested Service not found» exception.

{System.Runtime.Remoting.RemotingException: Requested Service not found

Server stack trace: at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders&
responseHeaders, Stream& responseStream)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at RemoteExampleServer.MyRemoteServerClass.DoSomething()
at RemoteExampleClient.Form1.button1_Click(Object sender, EventArgs e) in c:AaronRemoteExampleClientForm1.cs:line 30} System.Exception {System.Runtime.Remoting.RemotingException}

What am I doing wrong? Note, I’ve allowed access for these apps through the firewall (and I get the same behavior when I completely disable the firewall). I have no other security software on my computer.

Thanks,

Aaron

PS. I’d prefer solutions that don’t involve modifications to the ‘App.config’ xml. If at all possible, I’d like the .Net remote connection to be configured in code-space.

When using .NET Remoting to develop cross-process applications, you may encounter some exceptions. Because these anomalies are very simple in the posterior, but they are not clear when there are various anomalies at the beginning, so I have compiled these anomalies in this article for the convenience of friends to check through search engines.


This article content

    • Failed to connect to IPC port: The system cannot find the file specified
    • The requested service could not be found
    • Channel «ipc» is already registered

Failed to connect to IPC port: The system cannot find the file specified

System.Runtime.Remoting.RemotingException: «Failed to connect to IPC port: The system cannot find the file specified.»

Or English version:

System.Runtime.Remoting.RemotingException: Failed to connect to an IPC Port: The system cannot find the file specified.

When this exception occurs, it means that you have acquired a remote object, but when you use this object, you have not even registered the IPC port.

For example, the following code is a crude way of registering an IPC port, the incomingportName It is the Uri path prefix of IPC. For example, I can pass inwalterlv, The format of such an IPC object is approximately similar toipc://walterlv/xxx

private static void RegisterChannel(string portName)
{
    var serverProvider = new BinaryServerFormatterSinkProvider
    {
        TypeFilterLevel = TypeFilterLevel.Full,
    };
    var clientProvider = new BinaryClientFormatterSinkProvider();
    var properties = new Hashtable
    {
        ["portName"] = portName
    };
    var channel = new IpcChannel(properties, clientProvider, serverProvider);
    ChannelServices.RegisterChannel(channel, false);
}

When trying to accessipc://walterlv/foo Object and call its method, if you connectwalterlv Ports are not registered, it will appearFailed to connect to IPC port: The system cannot find the file specified. abnormal.

If you are already registeredwalterlv Port, but nofoo Object, another error appearsThe requested service could not be found, Please see the next section.

The requested service could not be found

System.Runtime.Remoting.RemotingException: «The requested service could not be found»

Or English version:

System.Runtime.Remoting.RemotingException: Requested Service not found

When this exception occurs, there are three possible reasons:

  1. The remote object to be searched has not been created;
  2. The remote object to be found has been recovered;
  3. No matching method was used to create and access objects.

More specifically, for the first case, when you try to access an object across processes, the object has not been created yet. What you need to do is to control the timing of object creation. The process that creates the object needs to complete the creation and marshaling of the object earlier than the process that accesses it. That is, the following code needs to be called first.

RemotingServices.Marshal(@object, typeof(TObject).Name, typeof(TObject));

In the second case, you may need to manually handle the life cycle of the marshaled object. RewriteInitializeLifetimeService Method and returnnull It is a lazy but effective method.

namespace Walterlv.Remoting.Framework
{
    public abstract class RemoteObject : MarshalByRefObject
    {
        public sealed override object InitializeLifetimeService() => null;
    }
}

For the third case, you need to check how you registered the .NET Remoting channel. The creation and access methods must match.

Channel «ipc» is already registered

System.Runtime.Remoting.RemotingException: «The channel «ipc» is already registered.»

In the same process,IpcChannel Default channel name of the classIpcChannel.ChannelName Value is a string"ipc". If you don’t pass its parametersproperties To specify["name"] = "Another name", Then you can’t callChannelServices.RegisterChannel To call this channel.

To put it simply, it is the above methodRegisterChannel You cannot call twice in a process, even if"portName" No difference. Usually you don’t need to call twice, if you must, please passHashTable Modifyname Attributes.


Reference

  • c# — .Net remoting error “Requested Service not found” — Stack Overflow

My blog will start athttps://blog.walterlv.com/, And CSDN will select and publish from it, but once it is published, it is rarely updated.

If you see anything you don’t understand on the blog, please communicate. I builtdotnet Vocational and Technical College Everyone is welcome to join.

This work usesCreative Commons Attribution-Non-commercial Use-Same Way Sharing 4.0 International License AgreementMake permission. Welcome to reprint, use, and republish, but be sure to keep the article’s signature Lu Yi (including link:), shall not be used for commercial purposes, and the modified works based on this article must be released under the same license. If you have any questions, pleaseContact me。

  • Remove From My Forums
  • Question

  • Dear all,

    I have the call to windows service but find that it prompted below error: Do you know how to solve??

    //————————————————————————-

    {System.Runtime.Remoting.RemotingException: Requested Service not found

    Server stack trace:
       at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders,
    Stream& responseStream)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at KDS.DAL.Messages.RMT_KDS.send2KDSItems(TransSummaryVO trans)
       at StoreServer.DAL.SendToKDS.COM_MessageSender.send2KDSItems(TransSummaryVO items) in C:vs2010SingleStore_RestaurantStoreServerStoreServer.DALSendToKDSCOM_MessageSender.cs:line 30}

    • Moved by

      Monday, August 27, 2012 10:17 AM
      (From:Visual C# General)

Answers

  • BinaryServerFormatterSinkProvider serverProv =
           new BinaryServerFormatterSinkProvider();
                        serverProv.TypeFilterLevel = TypeFilterLevel.Full;
                        RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;

                    serverProv.TypeFilterLevel = TypeFilterLevel.Full;
                        IDictionary propBag = new Hashtable();

                        bool isSecure = false;
                        propBag[«port»] = StoreServer.VO.Common.PropertiesVO.KDS_IPPORT;

                        propBag[«typeFilterLevel»] = TypeFilterLevel.Full;

                        propBag[«name»] = «UniqueChannelName»;  //right here raymond!!

                        tcpChannel = new TcpChannel(propBag, null, serverProv);
                        ChannelServices.RegisterChannel(tcpChannel, isSecure);

    • Marked as answer by
      Raymond Chiu
      Thursday, August 30, 2012 8:45 AM

Questions in SO normally contain a summary of the code that poses problem, not a link to a complete project.

As you’re new, I have taken a look anyway.

I could reproduce the problem, but not being a .NET remoting expert, I do not know what should be fixed in the part of the config. An internet search returns a lot of samples that use the tag for registration.

If you replace your client config by:

        <client>
            <wellknown
            type="MyRemoteObject.Greetings,MyRemoteObject"
            url="tcp://localhost:8737/ComponentHost" />
        </client>        

and the server config by:

  <service>
      <wellknown
      mode="Singleton"
      type="MyRemoteObject.Greetings,MyRemoteObject"
      objectUri="ComponentHost"/>
  </service>

It works fine.

Понравилась статья? Поделить с друзьями:
  • Ошибка request failed with status code 503
  • Ошибка romeo c 30 116 the division
  • Ошибка request failed with status code 500 аршин
  • Ошибка rom ваз 2115 инжектор
  • Ошибка request failed with status code 413