I am developing a simple .NET remoting server using an HTTP channel and SOAP formatter, and ran into a problem earlier with invalid SOAP actions. When invoking a method on a remoted object I was getting the following error message:
Unhandled Exception: System.Runtime.Remoting.RemotingException:
Invalid SOAPAction specified: blah blah blah
After trawling the web for an hour I established that many other developers are running into the same problem. Now that I’ve resolved the issue I wanted to share the solution with everyone else.
My simple remoting server is a MarshalByRef class, called MyAgent,
hosted in a Windows service. The HTTP channel, SOAP formatter, and
exposed remoted class are configured in the service application
configuration file as follows.
<wellknown mode=”SingleCall” type=”MyNamespace.MyAgent, MyAgentLib” objectUri=”MyAgent” />
<channel port=”8050″ ref=”http”>
In my client application, I configure the HTTP channel, SOAP formatter, and remote service class as follows:
<wellknown type=”MyNamespace.MyAgent, MyAgentLib” url=”MyAgent”/>
<channel ref=”http” port=”0″>
Originally, the MyAgent class
was a shared C# code file, compiled into both client and server
projects (in remoting, both client and server require the remoted class
type) – this worked fine in another remoting project I wrote, which
used IPC and TCP channels. When using the HTTP channel and SOAP
provider this approach does not work (using HTTP and binary formatter
gave me a different cryptic error). For some reason, the remoting
proxy (generated by the .NET remoting infrastructure) gets confused and
sees the client version of MyAgent class to be different to that of the MyAgent class hosted in the remote server. To fix the problem I created a shared class library, called MyAgentLib, and included the MyAgent class. I then pointed both client and server projects to the shared class library. Tada!