internal DiscoveryClientProtocol(HttpWebClientProtocol protocol) : base(protocol) { this.references = new DiscoveryClientReferenceCollection(); this.documents = new DiscoveryClientDocumentCollection(); this.inlinedSchemas = new Hashtable(); this.additionalInformation = new ArrayList(); this.errors = new DiscoveryExceptionDictionary(); }
public WebReference (DiscoveryClientDocumentCollection documents, CodeNamespace proxyCode) { if (documents == null) throw new ArgumentNullException ("documents"); if (proxyCode == null) throw new ArgumentNullException ("proxyCode"); _documents = documents; _proxyCode = proxyCode; }
public WebReference (DiscoveryClientDocumentCollection documents, CodeNamespace proxyCode, string protocolName, string appSettingUrlKey, string appSettingBaseUrl) { if (documents == null) throw new ArgumentNullException ("documents"); if (proxyCode == null) throw new ArgumentNullException ("proxyCode"); _documents = documents; _proxyCode = proxyCode; _protocolName = protocolName; _appSettingUrlKey = appSettingUrlKey; _appSettingBaseUrl = appSettingBaseUrl; }
/// <include file='doc\ServiceDescriptionImporter.uex' path='docs/doc[@for="WebReference.WebReference"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public WebReference(DiscoveryClientDocumentCollection documents, CodeNamespace proxyCode, string protocolName, string appSettingUrlKey, string appSettingBaseUrl) { // parameter check if (documents == null) { throw new ArgumentNullException("documents"); } if (proxyCode == null) { // no namespace throw new ArgumentNullException("proxyCode"); } if (appSettingBaseUrl != null && appSettingUrlKey == null) { throw new ArgumentNullException("appSettingUrlKey"); } this.protocolName = protocolName; this.appSettingUrlKey = appSettingUrlKey; this.appSettingBaseUrl = appSettingBaseUrl; this.documents = documents; this.proxyCode = proxyCode; }
public override void GenerateCode (AssemblyBuilder assemblyBuilder) { CodeCompileUnit unit = new CodeCompileUnit (); CodeNamespace proxyCode = new CodeNamespace (); unit.Namespaces.Add (proxyCode); var description = ServiceDescription.Read (OpenReader ()); var discCollection = new DiscoveryClientDocumentCollection () { {VirtualPath, description} }; var webref = new WebReferenceCollection () { new WebReference (discCollection, proxyCode) }; var options = new WebReferenceOptions (); options.Style = ServiceDescriptionImportStyle.Client; ServiceDescriptionImporter.GenerateWebReferences (webref, assemblyBuilder.CodeDomProvider, unit, options); assemblyBuilder.AddCodeCompileUnit (unit); }
public DiscoveryClientDocumentCollection GetDocuments() { return documents ?? (documents = DiscoverDocuments()); }
private static Assembly GenerateAssembly(string asmxFile) { string strWsdl = WsdlFromUrl(GetApplicationPath() + "/" + asmxFile + "?wsdl"); // Xml text reader StringReader wsdlStringReader = new StringReader(strWsdl); XmlTextReader tr = new XmlTextReader(wsdlStringReader); ServiceDescription sd = ServiceDescription.Read(tr); tr.Close(); // WSDL service description importer CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); CodeNamespace codeNamespaceFluorine = new CodeNamespace("FluorineFx"); codeCompileUnit.Namespaces.Add(codeNamespaceFluorine); CodeNamespace codeNamespace = new CodeNamespace(FluorineConfiguration.Instance.WsdlProxyNamespace); codeCompileUnit.Namespaces.Add(codeNamespace); #if (NET_1_1) ServiceDescriptionImporter sdi = new ServiceDescriptionImporter(); sdi.AddServiceDescription(sd, null, null); sdi.ProtocolName = "Soap"; sdi.Import(codeNamespace, codeCompileUnit); CSharpCodeProvider provider = new CSharpCodeProvider(); #else // Create a WSDL collection. DiscoveryClientDocumentCollection wsdlCollection = new DiscoveryClientDocumentCollection(); wsdlCollection.Add(asmxFile, sd); // Create a web refererence using the WSDL collection. WebReference reference = new WebReference(wsdlCollection, codeNamespace); reference.ProtocolName = "Soap12"; // Create a web reference collection. WebReferenceCollection references = new WebReferenceCollection(); references.Add(reference); WebReferenceOptions options = new WebReferenceOptions(); options.Style = ServiceDescriptionImportStyle.Client; options.CodeGenerationOptions = CodeGenerationOptions.None; options.SchemaImporterExtensions.Add(typeof(DataTableSchemaImporterExtension).AssemblyQualifiedName); CSharpCodeProvider provider = new CSharpCodeProvider(); ServiceDescriptionImporter.GenerateWebReferences(references, provider, codeCompileUnit, options); // Compile a proxy client //provider.GenerateCodeFromCompileUnit(codeCompileUnit, Console.Out, new CodeGeneratorOptions()); #endif //http://support.microsoft.com/default.aspx?scid=kb;en-us;326790 //http://pluralsight.com/wiki/default.aspx/Craig.RebuildingWsdlExe if (!FluorineConfiguration.Instance.WsdlGenerateProxyClasses) { //Strip any code that isn't the proxy class itself. foreach (CodeNamespace cns in codeCompileUnit.Namespaces) { // Remove anything that isn't the proxy itself ArrayList typesToRemove = new ArrayList(); foreach (CodeTypeDeclaration codeType in cns.Types) { bool webDerived = false; foreach (CodeTypeReference baseType in codeType.BaseTypes) { if (baseType.BaseType == "System.Web.Services.Protocols.SoapHttpClientProtocol") { webDerived = true; break; } } if (!webDerived) typesToRemove.Add(codeType); else { CodeAttributeDeclaration codeAttributeDeclaration = new CodeAttributeDeclaration(typeof(FluorineFx.RemotingServiceAttribute).FullName); codeType.CustomAttributes.Add(codeAttributeDeclaration); foreach (CodeTypeMember member in codeType.Members) { CodeConstructor ctor = member as CodeConstructor; if (ctor != null) { // We got a constructor // Add CookieContainer code // this.CookieContainer = new System.Net.CookieContainer(); //Session Cookie CodeSnippetStatement statement = new CodeSnippetStatement("this.CookieContainer = new System.Net.CookieContainer(); //Session Cookie"); ctor.Statements.Add(statement); } } } } foreach (CodeTypeDeclaration codeType in typesToRemove) { codeNamespace.Types.Remove(codeType); } } } else { foreach (CodeNamespace cns in codeCompileUnit.Namespaces) { foreach (CodeTypeDeclaration codeType in cns.Types) { bool webDerived = false; foreach (CodeTypeReference baseType in codeType.BaseTypes) { if (baseType.BaseType == "System.Web.Services.Protocols.SoapHttpClientProtocol") { webDerived = true; break; } } if (webDerived) { CodeAttributeDeclaration codeAttributeDeclaration = new CodeAttributeDeclaration(typeof(FluorineFx.RemotingServiceAttribute).FullName); codeType.CustomAttributes.Add(codeAttributeDeclaration); foreach (CodeTypeMember member in codeType.Members) { CodeConstructor ctor = member as CodeConstructor; if (ctor != null) { // We got a constructor // Add CookieContainer code // this.CookieContainer = new System.Net.CookieContainer(); //Session Cookie CodeSnippetStatement statement = new CodeSnippetStatement("this.CookieContainer = new System.Net.CookieContainer(); //Session Cookie"); ctor.Statements.Add(statement); } } } } } } if (FluorineConfiguration.Instance.ImportNamespaces != null) { for (int i = 0; i < FluorineConfiguration.Instance.ImportNamespaces.Count; i++) { ImportNamespace importNamespace = FluorineConfiguration.Instance.ImportNamespaces[i]; codeNamespace.Imports.Add(new CodeNamespaceImport(importNamespace.Namespace)); } } // source code generation StringBuilder srcStringBuilder = new StringBuilder(); StringWriter sw = new StringWriter(srcStringBuilder); #if (NET_1_1) ICodeGenerator icg = provider.CreateGenerator(); icg.GenerateCodeFromCompileUnit(codeCompileUnit, sw, null); #else provider.GenerateCodeFromCompileUnit(codeCompileUnit, sw, null); #endif string srcWSProxy = srcStringBuilder.ToString(); sw.Close(); // assembly compilation. CompilerParameters cp = new CompilerParameters(); cp.ReferencedAssemblies.Add("System.dll"); cp.ReferencedAssemblies.Add("System.Data.dll"); cp.ReferencedAssemblies.Add("System.Xml.dll"); cp.ReferencedAssemblies.Add("System.Web.Services.dll"); foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (assembly.GlobalAssemblyCache) { //Only System namespace if (assembly.GetName().Name.StartsWith("System")) { if (!cp.ReferencedAssemblies.Contains(assembly.GetName().Name + ".dll")) cp.ReferencedAssemblies.Add(assembly.Location); } } else { if (assembly.GetName().Name.StartsWith("mscorlib")) continue; //if( assembly.Location.ToLower().StartsWith(System.Web.HttpRuntime.CodegenDir.ToLower()) ) // continue; try { if (assembly.Location != null && assembly.Location != string.Empty) cp.ReferencedAssemblies.Add(assembly.Location); } catch (NotSupportedException) { //NET2 } } } cp.GenerateExecutable = false; //http://support.microsoft.com/kb/815251 //http://support.microsoft.com/kb/872800 cp.GenerateInMemory = false;//true; cp.IncludeDebugInformation = false; #if (NET_1_1) ICodeCompiler icc = provider.CreateCompiler(); CompilerResults cr = icc.CompileAssemblyFromSource(cp, srcWSProxy); #else CompilerResults cr = provider.CompileAssemblyFromSource(cp, srcWSProxy); #endif if (cr.Errors.Count > 0) { StringBuilder sbMessage = new StringBuilder(); sbMessage.Append(string.Format("Build failed: {0} errors", cr.Errors.Count)); if (log.IsErrorEnabled) log.Error(__Res.GetString(__Res.Wsdl_ProxyGenFail)); foreach (CompilerError e in cr.Errors) { log.Error(__Res.GetString(__Res.Compiler_Error, e.Line, e.Column, e.ErrorText)); sbMessage.Append("\n"); sbMessage.Append(e.ErrorText); } StringBuilder sbSourceTrace = new StringBuilder(); sbSourceTrace.Append("Attempt to compile the generated source code:"); sbSourceTrace.Append(Environment.NewLine); StringWriter swSourceTrace = new StringWriter(sbSourceTrace); IndentedTextWriter itw = new IndentedTextWriter(swSourceTrace, " "); provider.GenerateCodeFromCompileUnit(codeCompileUnit, itw, new CodeGeneratorOptions()); itw.Close(); log.Error(sbSourceTrace.ToString()); throw new FluorineException(sbMessage.ToString()); } return cr.CompiledAssembly; }
public WebReference(DiscoveryClientDocumentCollection documents, CodeNamespace proxyCode, string appSettingUrlKey, string appSettingBaseUrl) : this(documents, proxyCode, null, appSettingUrlKey, appSettingBaseUrl) { }
public WebReference(DiscoveryClientDocumentCollection documents, CodeNamespace proxyCode) : this(documents, proxyCode, null, null, null) { }
/* protected override IList GetMethodParameterAttributes(MethodInfo method, ParameterInfo paramInfo) { IList attrs = base.GetMethodParameterAttributes(method, paramInfo); // Add the XmlElementAttribute if needed XmlMemberMapping inMemberMapping = inputMembersMapping[paramInfo.Position]; if (inMemberMapping.Namespace != inputMembersMapping.Namespace) { CustomAttributeBuilderBuilder cabb = new CustomAttributeBuilderBuilder(typeof(XmlElementAttribute)); cabb.AddPropertyValue("Namespace", inMemberMapping.Namespace); attrs.Add(cabb.Build()); } return attrs; } */ #endregion #region Private Methods private void Initialize(DiscoveryClientDocumentCollection wsDocuments, string bindingName) { // Service descriptions this.wsDescriptions = new ServiceDescriptionCollection(); XmlSchemas schemas = new XmlSchemas(); foreach (DictionaryEntry entry in wsDocuments) { if (entry.Value is ServiceDescription) { this.wsDescriptions.Add((ServiceDescription)entry.Value); } if (entry.Value is XmlSchema) { schemas.Add((XmlSchema)entry.Value); } } // XmlSchemaImporter foreach (ServiceDescription serviceDescription in this.wsDescriptions) { foreach (XmlSchema schema in serviceDescription.Types.Schemas) { if (schemas[schema.TargetNamespace] == null) { schemas.Add(schema); } } } this.schemaImporter = new XmlSchemaImporter(schemas); this.wsBinding = GetWsBinding(this.wsDescriptions, bindingName); this.wsUrl = GetWsUrl(this.wsDescriptions, this.wsBinding); }
/// <summary> /// Creates a new instance of the /// <see cref="SoapHttpClientProxyTypeBuilder"/> class. /// </summary> /// <param name="serviceUri">The URI that contains the Web Service meta info (WSDL).</param> /// <param name="wsDocuments">The XML Web Service documents to use to create the proxy.</param> /// <param name="bindingName">The name of the Web Service binding to use.</param> public SoapHttpClientProxyTypeBuilder(IResource serviceUri, DiscoveryClientDocumentCollection wsDocuments, string bindingName) { this.serviceUri = serviceUri; Name = "SoapHttpClientProxy"; ProxyTargetAttributes = false; Initialize(wsDocuments, bindingName); }
/// <summary> /// Gets XML Web Services documents from a Spring resource. /// </summary> private DiscoveryClientDocumentCollection GetWsDocuments(IResource resource) { try { if (ServiceUri is UrlResource || ServiceUri is FileSystemResource) { DiscoveryClientProtocol dcProtocol = new DiscoveryClientProtocol(); dcProtocol.AllowAutoRedirect = true; dcProtocol.Credentials = CreateCredentials(); dcProtocol.Proxy = ConfigureProxy(); dcProtocol.DiscoverAny(resource.Uri.AbsoluteUri); dcProtocol.ResolveAll(); return dcProtocol.Documents; } else { DiscoveryClientDocumentCollection dcdc = new DiscoveryClientDocumentCollection(); dcdc[resource.Description] = ServiceDescription.Read(resource.InputStream); return dcdc; } } catch (Exception ex) { throw new ArgumentException(String.Format("Couldn't retrieve the description of the web service located at '{0}'.", resource.Description), ex); } }