Microsoft KB Archive/828987

= BUG: A Client That Is Linked with the Soapsuds Proxy DLL Throws a Remoting Exception at Run Time =

Article ID: 828987

Article Last Modified on 4/19/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1

-





SYMPTOMS
When a client is linked with the proxy DLL that the Soapsuds tool (Soapsuds.exe) generates, the client throws a remoting exception at run time. You may receive an error message that is similar to the following error message:

Unhandled Exception: System.Runtime.Remoting.RemotingException: Permission denied for activating type soap:TestClass, http://schemas.microsoft.com/clr/nsassem/EchoExeTest/ServerExe%2C%20Version%3D0.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull. Server stack trace: at System.Runtime.Remoting.Activation.ActivationListener.Activate(IConstructionCallMessage ctorMsg) at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)



WORKAROUND
To work around this problem by linking the client, follow these steps:   Run the Remoting Server application, and then generate the proxy by using the following command: soapsuds -url: -oa:serverexe.dll  Run the remoting server.   Generate the proxy code by using the following command: soapsuds -url: -gc  Open the .cs file that Soapsuds.exe generates, remove the SoapType attribute from the class, and then build the proxy. Link the proxy to the client, and then run Soapsuds.exe.

Note If the remoting server is not running, Soapsuds.exe generates an error and does not generate the proxy code.</ol> </li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce the Problem
<ol>  Use Notepad to create a text file. Paste the following code in the file: <system.runtime.remoting> <application name=&quot;ServerExe&quot;> <channel port=&quot;9998&quot; type=&quot;System.Runtime.Remoting.Channels.Http.HttpChannel, System.Runtime.Remoting,Version=1.0.5000.00, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; > <serverProviders> <provider ref=&quot;wsdl&quot; metadataEnabled=&quot;true&quot; remoteApplicationMetadataEnabled=&quot;true&quot; /> <formatter ref=&quot;soap&quot; typeFilterLevel=&quot;Full&quot; /> <formatter ref=&quot;binary&quot; typeFilterLevel=&quot;Low&quot; /> </serverProviders> <channel port=&quot;9999&quot; type=&quot;System.Runtime.Remoting.Channels.Tcp.TcpChannel, System.Runtime.Remoting,Version=1.0.5000.00, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; /> </system.runtime.remoting> </li> Save the file as C:\ServerChannels.config .</li>  Use Notepad to create a new text file. Paste the following code in the file: <system.runtime.remoting>

<activated type=&quot;EchoExeTest.TestClass, ServerExe&quot; />

</system.runtime.remoting> </li> Save the file as C:\ServerCao.cfg .</li>  Use Notepad to create a new text file. Paste the following code in the file: using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Metadata; using System.Runtime.Remoting.Metadata.W3cXsd2001;

namespace EchoExeTest{ [Serializable] public class testObject {       public int x;        public int y;    } [Serializable] public struct testStruct {       public int x;        public int y;    } public class Server {

public static int Main(string [] args) { Server servObj = new Server; servObj.Initialize(args); System.Console.WriteLine(&quot;Press ENTER to exit.&quot;); System.Console.ReadLine; return 0; }

public void Usage { Console.WriteLine(&quot; Usage : ServerExe -chan:channel.config -mode:mode.config&quot;); }

public int Initialize(string[] args) { int ret=0;

if (args.Length == 0) Usage; for (int i=0;i<args.Length;i++) { if (                   String.Compare(args[i],&quot;HELP&quot;, true) == 0 ||                    String.Compare(args[i],&quot;?&quot;, true) == 0 ||                    String.Compare(args[i],&quot;/h&quot;, true) == 0 ||                    String.Compare(args[i],&quot;-h&quot;, true) == 0 ||                    String.Compare(args[i],&quot;-?&quot;, true) == 0 ||                    String.Compare(args[i],&quot;/?&quot;, true) == 0                ) { Usage; return -1; }

String arg = args[i]; String value = null;

if (args[i][0] == '/' || args[i][0] == '-'){ int index = args[i].IndexOf(':'); if (index != -1) {

arg = args[i].Substring(1, index-1); //Make sure that a colon is not the last character. if (index == (args[i].Length - 1)) throw new Exception(&quot;Argument cannot be empty -> &quot; + args[i]); value = args[i].Substring(index+1); }                   else arg = args[i].Substring(1); }

//Process the input sources. if (String.Compare(arg, &quot;chan&quot;, true) == 0) { RemotingConfiguration.Configure(value); }               else if (String.Compare(arg, &quot;mode&quot;, true) == 0) { RemotingConfiguration.Configure(value); }              }               ret=100; return ret; }

}

public class TestClass : MarshalByRefObject { public int EchoInt(int intval) { Console.WriteLine(&quot;Method Called&quot;); return intval; }            public string EchoString(string strval) { Console.WriteLine(&quot;Method Called&quot;); return strval; }       public DateTime EchoDateTime(DateTime dval) { return dval; }       public void voidFunc{ return; }       public int EchoParam(int intval) { return intval; }       public void SendParam(int intval) { return; }       public int GetParam { return 10; }       public int EchoRefParam(ref int intval) { intval++; return 100; }       public void SendRefParam(ref int intval) { intval++; return; }       public void OutParam(out int intval) { intval=100; }          public testStruct echoStruct(testStruct ts) { return ts; }       public testObject echoObject(testObject to) { Console.WriteLine(&quot;Method Called&quot;); return to; }       public int[] echoArray(int[] intArray) { return intArray; }   }

} </li> Save the file as ServerExe.cs .</li>  Use Notepad to create a new text file. Paste the following code in the file: <system.runtime.remoting> <application name=&quot;ClientExe&quot;> <channel port=&quot;0&quot; type=&quot;System.Runtime.Remoting.Channels.Http.HttpChannel, System.Runtime.Remoting,Version=1.0.5000.00, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; /> <channel port=&quot;0&quot; type=&quot;System.Runtime.Remoting.Channels.Tcp.TcpChannel, System.Runtime.Remoting,Version=1.0.5000.00, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot; />

</system.runtime.remoting> </li> Save the file as C:\ClientChannels.config .</li>  Use Notepad to create a new text file. Paste the following code in the file: <system.runtime.remoting>

<client url=&quot;http://localhost:9998/&quot; > <activated type=&quot;EchoExeTest.TestClass, ServerExe&quot; url=&quot;http://localhost:9998/TestClass.soap&quot; /> </system.runtime.remoting> </li> Save the file as C:\HttpCaoClient.cfg .</li>  Use Notepad to create a new text file. Paste the following code in the file: using System; using System.Runtime.Remoting; using EchoExeTest;

public class ClientExeClass {   public static int Main(String[] args) {       const int PASS = 0xABBA; int parint = 12, outInt; string parstring = &quot;hello&quot;; DateTime pardatetime = DateTime.Now; testStruct tStruct = new testStruct; tStruct.x = 100 ; tStruct.y = 200; testObject tObject = new testObject; tObject.x = 100 ; tObject.y = 200;

Console.WriteLine(&quot;Start initiating the object.&quot;); ClientExeClass cec = new ClientExeClass; cec.Initialize(args); TestClass tClass = new TestClass; if(tClass == null){ Console.WriteLine(&quot;Object not activated.&quot;); return 0; }

try{ Console.WriteLine(&quot;Calling methods on the object.&quot;); int retInt = tClass.EchoInt(parint); if(retInt != parint) throw new Exception(&quot;Failure in EchoInt method.&quot;); String retString = tClass.EchoString(parstring); if(retString != parstring) throw new Exception(&quot;Failure in EchoString method.&quot;);

DateTime retDval = tClass.EchoDateTime(pardatetime); if(retDval != pardatetime) throw new Exception(&quot;Failure in EchoDateTime method.&quot;);

tClass.voidFunc; tClass.SendParam(parint); retInt = tClass.GetParam; if(retInt != 10) throw new Exception(&quot;Failure in GetParam method.&quot;);

tClass.SendRefParam(ref parint); if(parint != 13) throw new Exception(&quot;Failure in SendRefParam method.&quot;);

retInt = tClass.EchoRefParam( ref parint); if((retInt != 100) || (parint != 14)) throw new Exception(&quot;Failure in EchoRefParam method.&quot;);

tClass.OutParam(out outInt); if(outInt != 100) throw new Exception(&quot;Failure in OutParam method.&quot;);

testStruct retStruct = tClass.echoStruct(tStruct); if( (retStruct.x != tStruct.x) ||               (retStruct.y != tStruct.y)) throw new Exception(&quot;Failure in echoStruct method.&quot;);

testObject retObject = tClass.echoObject(tObject); if( (retObject.x != tObject.x) ||               (retObject.y != tObject.y)) throw new Exception(&quot;Failure in echoObject method.&quot;);

int[] parArray = new int[2]; parArray[0]=1; parArray[1]=2;

int[] retArray = tClass.echoArray(parArray); if( (retArray[0] != parArray[0]) ||               (retArray[1] != parArray[1])) throw new Exception(&quot;Failure in echoArray method.&quot;);

}catch (Exception e) { Console.WriteLine(e); return 0; }

return PASS; }   public void Usage { Console.WriteLine(&quot; Usage : ClientExe -chan:Client.config -mode:wko/cao?client.config&quot;); }

public void Initialize(string[] args) { int ret=0;

if (args.Length == 0) Usage; for (int i=0;i<args.Length;i++) { if (           String.Compare(args[i],&quot;HELP&quot;, true) == 0 ||            String.Compare(args[i],&quot;?&quot;, true) == 0 ||            String.Compare(args[i],&quot;/h&quot;, true) == 0 ||            String.Compare(args[i],&quot;-h&quot;, true) == 0 ||            String.Compare(args[i],&quot;-?&quot;, true) == 0 ||            String.Compare(args[i],&quot;/?&quot;, true) == 0        ) { Usage; return; }

String arg = args[i]; String value = null;

if (args[i][0] == '/' || args[i][0] == '-'){ int index = args[i].IndexOf(':'); if (index != -1) {

arg = args[i].Substring(1, index-1); //Make sure that a colon is not the last character. if (index == (args[i].Length - 1)) throw new Exception(&quot;Argument cannot be empty. -> &quot; + args[i]); value = args[i].Substring(index+1); }           else arg = args[i].Substring(1); }

//Process the input sources. if (String.Compare(arg, &quot;chan&quot;, true) == 0) { Console.WriteLine(value); RemotingConfiguration.Configure(value); }       else if (String.Compare(arg, &quot;mode&quot;, true) == 0) { Console.WriteLine(value); RemotingConfiguration.Configure(value); }          }           return; }

} </li> Save the file as C:\ClientExe.cs .</li>  Use Notepad to create a new text file. Paste the following code in the file: csc ServerExe.cs start serverexe -chan:serverchannels.config -mode:servercao.cfg soapsuds -url:http://localhost:9998/remoteapplicationmetadata.rem?Wsdl -oa:serverexe.dll csc /r:serverexe.dll clientexe.cs clientexe -chan:clientchannels.config -mode:httpcaoclient.cfg </li> Save the file as c:\Build.bat .</li> For Visual Studio .NET 2002, click Start, point to Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt.

For Visual Studio .NET 2003, click Start, point to Programs, point to Microsoft Visual Studio .NET 2003, point to Visual Studio .NET Tools, and then click Visual Studio .NET 2003 Command Prompt.</li> At the command prompt, type C:, and then press the ENTER key.</li> <li>Type Build.bat, and then press the ENTER key.</li> <li>Run the remoting server application and the remoting client application.

You may receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.

</li></ol>

<div class="references_section">