none
Dynamic proxies RRS feed

  • Question

  • I want to write an utility to generate the proxies for SAP BAPI/RFC dynamically. please suggest

    Taruna

    Tuesday, January 8, 2008 7:30 AM

Answers

  • Hi!

     

    Assume you have already used the MetadataRetrievalClient class to obtain the .wsdl from the adapter. You can then use the following code to convert the .wsdl to a .cs file:

     

    ----

     

    MetadataSection section = MetadataSection.CreateFromServiceDescription(System.Web.Services.Description.ServiceDescription.Read(@"C:\your.wsdl"));

    MetadataSet set = new MetadataSet(new MetadataSection[] { section });

    WsdlImporter importer = new WsdlImporter(set);

    CodeCompileUnit unit = new CodeCompileUnit();

    ServiceContractGenerator generator = new ServiceContractGenerator(unit);

    IEnumerable<ContractDescription> contracts = importer.ImportAllContracts();

    foreach (ContractDescription contractDescription in contracts)

    {

    generator.GenerateServiceContractType(contractDescription);

    }

    CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");

    using (StreamWriter sw = new StreamWriter(@"C:\out.cs"))

    {

    provider.GenerateCodeFromCompileUnit(unit, sw, new CodeGeneratorOptions());

    }

     

    -----

     

    You need to add references to System.configuration, System.Web.Services, System.Runtime.Serialization and System.ServiceModel.

     

    If you want to perform any other customizations, you should look up the help topics on the classes in MSDN.

    Wednesday, January 16, 2008 2:16 PM

All replies

  • You can use the MetadataRetrievalClient class to obtain WSDL from the adapter. You can then use the ServiceContractGenerator class (http://msdn2.microsoft.com/en-us/library/system.servicemodel.description.servicecontractgenerator.aspx) to generate the client and interface from your code.
    Tuesday, January 8, 2008 5:33 PM
  • Hi Mustansir,

    The link has sample code in which i dont know how to pass EndpointAddress, it gives me metadata resolve error? Is there any other way to do the same?

    Thanks

    Taruna

     

    Wednesday, January 16, 2008 7:41 AM
  • Hi!

     

    Assume you have already used the MetadataRetrievalClient class to obtain the .wsdl from the adapter. You can then use the following code to convert the .wsdl to a .cs file:

     

    ----

     

    MetadataSection section = MetadataSection.CreateFromServiceDescription(System.Web.Services.Description.ServiceDescription.Read(@"C:\your.wsdl"));

    MetadataSet set = new MetadataSet(new MetadataSection[] { section });

    WsdlImporter importer = new WsdlImporter(set);

    CodeCompileUnit unit = new CodeCompileUnit();

    ServiceContractGenerator generator = new ServiceContractGenerator(unit);

    IEnumerable<ContractDescription> contracts = importer.ImportAllContracts();

    foreach (ContractDescription contractDescription in contracts)

    {

    generator.GenerateServiceContractType(contractDescription);

    }

    CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");

    using (StreamWriter sw = new StreamWriter(@"C:\out.cs"))

    {

    provider.GenerateCodeFromCompileUnit(unit, sw, new CodeGeneratorOptions());

    }

     

    -----

     

    You need to add references to System.configuration, System.Web.Services, System.Runtime.Serialization and System.ServiceModel.

     

    If you want to perform any other customizations, you should look up the help topics on the classes in MSDN.

    Wednesday, January 16, 2008 2:16 PM
  •  

    You gave me wonderful code to generate the proxy class it worked with error and problems and generated the exact proxy class like MS adapter generates, too good.

    Thanks a lot for your help otherwise I would been struggling a lot to get it done. You are master.

    Thursday, January 17, 2008 11:55 AM