dausdashsan
dausdashsan

Reputation: 251

Use Svcutil.exe to make a proxy class which is usable

I'm trying to use svcutil.exe to make a proxy class. The proxy should in .dll, so that I can 'add reference' the library to another project and use it. Below are my current codes.

        ProcessStartInfo start = new ProcessStartInfo();
        start.Arguments = "/out:C:\\Temp\\myProxyClass.cs http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
        start.FileName = "C:\\Temp\\SvcUtil.lnk";
        start.WindowStyle = ProcessWindowStyle.Hidden;
        start.CreateNoWindow = true;

        using (Process proc = Process.Start(start))
        {
            proc.WaitForExit();
        }

        ProcessStartInfo start1 = new ProcessStartInfo();
        start1.Arguments = "/target:library /out:C:\\Temp\\XXX.dll C:\\Temp\\myProxyClass.cs";
        start1.FileName = "C:\\Temp\\csc.lnk";
        start1.WindowStyle = ProcessWindowStyle.Hidden;
        start1.CreateNoWindow = true;

        using (Process proc1 = Process.Start(start1))
        {
            proc1.WaitForExit();
        }

As shown in above, I use svcutil.exe to generate cs file first, then compile it using csc.exe to make as dll. When I add it as reference in another project and try to run it, I got an error.

Error 1 The type 'System.ServiceModel.ClientBase`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. C:\Users\ABC\My Work\AA-Private\Test\Test\Program.cs 13 13 Test

Upvotes: 0

Views: 193

Answers (1)

Todd
Todd

Reputation: 309

The error message tells you what you need to do. The project that you are adding your proxy dll to must also have a reference to System.ServiceModel in it.

Upvotes: 0

Related Questions