5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // Copyright (C) 2003 Ximian, Inc.
11 using System
.Reflection
;
12 using System
.Collections
;
13 using System
.Runtime
.Remoting
.MetadataServices
;
19 static void Main (string[] args
)
21 Runner run
= new Runner (args
);
22 AppDomain domain
= AppDomain
.CreateDomain ("runner", null, Directory
.GetCurrentDirectory(), "", false);
23 domain
.DoCallBack (new CrossAppDomainDelegate (run
.Main
));
30 static bool logo
= true;
31 static string inputUrl
= null;
32 static string inputTypes
= null;
33 static string inputSchema
= null;
34 static string inputAssembly
= null;
35 static string inputDirectory
= null;
37 static string serviceEndpoint
= null;
38 static string outputSchema
= null;
39 static string outputDirectory
= null;
40 static string outputAssembly
= null;
41 static bool outputCode
= false;
43 static bool wrappedProxy
= true;
44 static string proxyNamespace
= null;
45 static string strongNameFile
= null;
47 static string userName
= null;
48 static string password
= null;
49 static string domain
= null;
50 static string httpProxyName
= null;
51 static string httpProxyPort
= null;
55 public Runner (string[] args
)
64 ReadParameters (args
);
69 if (args
.Length
== 0 || args
[0] == "--help")
75 ArrayList types
= new ArrayList ();
76 Assembly assembly
= null;
78 if (inputAssembly
!= null)
80 assembly
= Assembly
.LoadFile (inputAssembly
);
81 foreach (Type t
in assembly
.GetTypes ())
82 types
.Add (new ServiceType (t
, serviceEndpoint
));
85 if (inputTypes
!= null)
87 string[] ts
= inputTypes
.Split (';');
88 foreach (string type
in ts
)
93 string[] typeParts
= type
.Split (',');
94 if (typeParts
.Length
== 1)
95 throw new Exception ("Type assembly not specified");
97 if (typeParts
.Length
>= 2)
99 t
= Type
.GetType (typeParts
[0] + ", " + typeParts
[1]);
100 if (typeParts
.Length
> 2)
103 types
.Add (new ServiceType (t
, url
));
107 ArrayList writtenFiles
= new ArrayList ();
108 MemoryStream schemaStream
= null;
112 schemaStream
= new MemoryStream ();
113 MetaData
.ConvertTypesToSchemaToStream ((ServiceType
[]) types
.ToArray (typeof(ServiceType
)), SdlType
.Wsdl
, schemaStream
);
116 if (inputUrl
!= null)
118 if (schemaStream
!= null) throw new Exception ("Only one type source can be specified");
119 schemaStream
= new MemoryStream ();
120 MetaData
.RetrieveSchemaFromUrlToStream (inputUrl
, schemaStream
);
123 if (inputSchema
!= null)
125 if (schemaStream
!= null) throw new Exception ("Only one type source can be specified");
126 schemaStream
= new MemoryStream ();
128 FileStream fs
= new FileStream (inputSchema
, FileMode
.Open
, FileAccess
.Read
);
129 byte[] buffer
= new byte [1024*5];
131 while ((nr
= fs
.Read (buffer
, 0, buffer
.Length
)) > 0)
132 schemaStream
.Write (buffer
, 0, nr
);
135 if (outputSchema
!= null)
137 if (schemaStream
== null) throw new Exception ("No input schema or assembly has been specified");
139 schemaStream
.Position
= 0;
140 MetaData
.SaveStreamToFile (schemaStream
, outputSchema
);
141 Console
.WriteLine ("Written file " + outputSchema
);
146 if (schemaStream
== null) throw new Exception ("No input schema or assembly has been specified");
148 schemaStream
.Position
= 0;
149 MetaData
.ConvertSchemaStreamToCodeSourceStream (wrappedProxy
, outputDirectory
, schemaStream
, writtenFiles
, null, null);
152 if (outputAssembly
!= null)
154 if (schemaStream
== null) throw new Exception ("No input schema or assembly has been specified");
156 schemaStream
.Position
= 0;
158 MetaData
.ConvertCodeSourceStreamToAssemblyFile (writtenFiles
, outputAssembly
, strongNameFile
);
161 MetaData
.ConvertSchemaStreamToCodeSourceStream (wrappedProxy
, outputDirectory
, schemaStream
, writtenFiles
, null, null);
162 MetaData
.ConvertCodeSourceStreamToAssemblyFile (writtenFiles
, outputAssembly
, strongNameFile
);
163 foreach (string file
in writtenFiles
)
165 writtenFiles
.Clear ();
167 writtenFiles
.Add (outputAssembly
);
170 foreach (string fn
in writtenFiles
)
171 Console
.WriteLine ("Written file " + fn
);
175 Console
.WriteLine ("ERROR: " + ex
.Message
);
176 if (ex
.GetType() != typeof(Exception
))
177 Console
.WriteLine (ex
);
179 Console
.WriteLine ();
182 static void WriteLogo ()
184 Console
.WriteLine ("Mono SOAPSUDS Tool");
185 Console
.WriteLine ();
188 static void WriteHelp ()
190 Console
.WriteLine ("Usage: soapsuds [inputs] [outputs] [options]");
191 Console
.WriteLine ();
192 Console
.WriteLine ("Inputs:");
193 Console
.WriteLine (" -url urltoschema:url Url from which to retrieve the schema");
194 Console
.WriteLine (" -types:type1,assembly[,serviceEndpoint][;type2,assembly,...] ");
195 Console
.WriteLine (" List of types from which to generate");
196 Console
.WriteLine (" a schema or proxy");
197 Console
.WriteLine (" -ia -inputassemblyfile:assembly Assembly that contains the types to export");
198 Console
.WriteLine (" -is -inputschemafile:schemafile Schema from which to generate proxy classes");
199 Console
.WriteLine ();
200 Console
.WriteLine ("Input Options:");
201 Console
.WriteLine (" -id -inputdirectory:directory Directory where DLLs are located");
202 Console
.WriteLine (" -se -serviceendpoint:url Url of the service to be placed in the");
203 Console
.WriteLine (" WSDL document");
204 Console
.WriteLine ();
205 Console
.WriteLine ("Outputs:");
206 Console
.WriteLine (" -oa -outputassemblyfile:assembly Generate an assembly");
207 Console
.WriteLine (" -os -outputschemafile:file Generate a schema");
208 Console
.WriteLine (" -gc -generatecode Generate proxy source code");
209 Console
.WriteLine ();
210 Console
.WriteLine ("Output Options:");
211 Console
.WriteLine (" -od -outputdirectory:directory Directory where output will be generated");
212 Console
.WriteLine (" -pn -proxynamespace:namespace Namespace of the generated proxy");
213 Console
.WriteLine (" -nowp -nowrappedproxy Generate a wrapped proxy");
214 Console
.WriteLine (" -wp -wrappedproxy Generate a wrapped proxy");
215 Console
.WriteLine (" -sn -strongnamefile:snfile Strong name file");
216 Console
.WriteLine ();
217 Console
.WriteLine ("General Options:");
218 Console
.WriteLine (" -u -username:name User name for server authentication");
219 Console
.WriteLine (" -p -password:pwd Password for server authentication");
220 Console
.WriteLine (" -d -domain:domain Domain of the server");
221 Console
.WriteLine (" -hpn -httpProxyName:name Name of http proxy");
222 Console
.WriteLine (" -hpp -httpProxyPort:port Port of http proxy");
223 Console
.WriteLine (" -nologo Supress the startup logo");
224 Console
.WriteLine ();
227 static void ReadParameters (string[] args
)
229 NetworkCredential cred
= new NetworkCredential ();
230 NetworkCredential proxyCred
= new NetworkCredential ();
231 WebProxy proxy
= new WebProxy ();
235 foreach (string arg
in args
)
237 if (!arg
.StartsWith ("/") && !arg
.StartsWith ("-"))
240 string parg
= arg
.Substring (1);
241 int i
= parg
.IndexOf (":");
244 param
= parg
.Substring (i
+1);
245 parg
= parg
.Substring (0,i
);
248 switch (parg
.ToLower ())
254 case "urltoschema": case "url":
262 case "inputassemblyfile": case "ia":
263 inputAssembly
= param
;
266 case "outputassemblyfile": case "oa":
267 outputAssembly
= param
;
270 case "inputdirectory": case "id":
271 inputDirectory
= param
;
274 case "outputdirectory": case "od":
275 outputDirectory
= param
;
278 case "inputschemafile": case "is":
282 case "outputschemafile": case "os":
283 outputSchema
= param
;
286 case "proxynamespace": case "pn":
287 proxyNamespace
= param
;
290 case "serviceendpoint": case "se":
291 serviceEndpoint
= param
;
294 case "strongnamefile": case "sn":
295 strongNameFile
= param
;
298 case "nowrappedproxy": case "nowp":
299 wrappedProxy
= false;
302 case "wrappedproxy": case "wp":
306 case "generatecode": case "gc":
310 case "username": case "u":
314 case "password": case "p":
318 case "domain": case "d":
322 case "httpProxyName": case "hpn":
323 httpProxyName
= param
;
326 case "httpProxyPort": case "hpp":
327 httpProxyPort
= param
;