public void WriteXml(XmlWriter xmlWriter) { if (wsdl != null) { using (MemoryStream ms = new MemoryStream()) { wsdl.Write(ms); XmlDictionaryReaderQuotas quota = new XmlDictionaryReaderQuotas(); quota.MaxDepth = 32; quota.MaxStringContentLength = 8192; quota.MaxArrayLength = 16384; quota.MaxBytesPerRead = 4096; quota.MaxNameTableCharCount = 16384; ms.Seek(0, SeekOrigin.Begin); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(ms, null, quota, null); if ((reader.MoveToContent() == XmlNodeType.Element) && (reader.Name == "wsdl:definitions")) { xmlWriter.WriteNode(reader, false); } reader.Close(); } } }
private static WsdlNS.ServiceDescription CloneWsdl(WsdlNS.ServiceDescription originalWsdl) { Fx.Assert(originalWsdl != null, "originalWsdl must not be null"); WsdlNS.ServiceDescription newWsdl; using (MemoryStream memoryStream = new MemoryStream()) { originalWsdl.Write(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); newWsdl = WsdlNS.ServiceDescription.Read(memoryStream); } return(newWsdl); }
public ServiceDescription Convert(XmlDocument wsdl2Xml) { CannonizePrefix(wsdl2Xml); var ser = new XmlSerializer(typeof(DescriptionType)); var reader = new StringReader(wsdl2Xml.OuterXml); var wsdl2 = (DescriptionType)ser.Deserialize(reader); var wsdl1 = new ServiceDescription(); ConvertDescription(wsdl2, wsdl1); ConvertImports(wsdl2, wsdl1); ConvertTypes(wsdl2, wsdl1); ConvertInterface(wsdl2, wsdl1); ConvertBinding(wsdl2, wsdl1); ConvertService(wsdl2, wsdl1); //not sure why needs to do it... but otherwise code generation fails var m = new MemoryStream(); wsdl1.Write(m); string s = Encoding.UTF8.GetString(m.GetBuffer()); wsdl1 = ServiceDescription.Read(new StringReader(s)); return wsdl1; }
public void SimpleWrite () { ServiceDescription sd = new ServiceDescription (); Assert.IsNull (sd.Name); sd.Write (TextWriter.Null); }
public static ArrayList GenerateWebProxyCode(Project project, ServiceDescription desc) { ArrayList fileList = null; string serviceName = String.Empty; if(desc.Services.Count > 0) { serviceName = desc.Services[0].Name; } else { serviceName = "UnknownService"; } string webRefFolder = "Web References"; string nmspace = GetNamespaceFromUri(desc.RetrievalUrl); StringBuilder savedir = new StringBuilder(); savedir.Append(project.BaseDirectory); savedir.Append(Path.DirectorySeparatorChar); savedir.Append(webRefFolder); savedir.Append(Path.DirectorySeparatorChar); savedir.Append(GetDirectoryFromUri(desc.RetrievalUrl) + Path.DirectorySeparatorChar + serviceName); // second, create the path if it doesn't exist if(!Directory.Exists(savedir.ToString())) Directory.CreateDirectory(savedir.ToString()); // generate the assembly ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.AddServiceDescription(desc, null, null); CodeNamespace codeNamespace = new CodeNamespace(nmspace); CodeCompileUnit codeUnit = new CodeCompileUnit(); codeUnit.Namespaces.Add(codeNamespace); importer.Import(codeNamespace, codeUnit); CodeDomProvider provider; System.CodeDom.Compiler.ICodeGenerator generator; String ext = String.Empty; switch(project.ProjectType) { case "C#": provider = new Microsoft.CSharp.CSharpCodeProvider(); ext = "cs"; break; case "VBNET": provider = new Microsoft.VisualBasic.VBCodeProvider(); ext = "vb"; break; default: // project type not supported error provider = null; break; } string filename = savedir.ToString() + Path.DirectorySeparatorChar + serviceName + "WebProxy." + ext; string wsdlfilename = savedir.ToString() + Path.DirectorySeparatorChar + serviceName + ".wsdl"; if(provider != null) { StreamWriter sw = new StreamWriter(filename); generator = provider.CreateGenerator(); CodeGeneratorOptions options = new CodeGeneratorOptions(); options.BracingStyle = "C"; generator.GenerateCodeFromCompileUnit(codeUnit, sw, options); sw.Close(); if(File.Exists(filename)) { fileList = new ArrayList(); // add project files to the list ProjectFile pfile = new ProjectFile(); pfile.Name = project.BaseDirectory + Path.DirectorySeparatorChar + webRefFolder; pfile.BuildAction = BuildAction.Nothing; pfile.Subtype = Subtype.WebReferences; pfile.DependsOn = String.Empty; pfile.Data = String.Empty; fileList.Add(pfile); /* pfile = new ProjectFile(); pfile.Name = project.BaseDirectory + @"\Web References\" + nmspace; pfile.BuildAction = BuildAction.Nothing; pfile.Subtype = Subtype.Directory; pfile.DependsOn = project.BaseDirectory + @"\Web References\"; pfile.WebReferenceUrl = String.Empty; fileList.Add(pfile); */ /* pfile = new ProjectFile(); pfile.Name = project.BaseDirectory + @"\Web References\" + nmspace + @"\" + serviceName; pfile.BuildAction = BuildAction.Nothing; pfile.Subtype = Subtype.Directory; pfile.DependsOn = project.BaseDirectory + @"\Web References\" + nmspace + @"\"; pfile.WebReferenceUrl = desc.RetrievalUrl; fileList.Add(pfile); */ // the Web Reference Proxy pfile = new ProjectFile(); pfile.Name = filename; pfile.BuildAction = BuildAction.Compile; pfile.Subtype = Subtype.Code; pfile.DependsOn = project.BaseDirectory + Path.DirectorySeparatorChar + webRefFolder; pfile.Data = desc.RetrievalUrl; fileList.Add(pfile); // the WSDL File used to generate the Proxy desc.Write(wsdlfilename); pfile = new ProjectFile(); pfile.Name = wsdlfilename; pfile.BuildAction = BuildAction.Nothing; pfile.Subtype = Subtype.Code; pfile.DependsOn = project.BaseDirectory + Path.DirectorySeparatorChar + webRefFolder; pfile.Data = desc.RetrievalUrl; fileList.Add(pfile); } } return fileList; }