Consuming WCF in NAtive Code via Managed Code in Visual COBOL

Hi Chris,

The objective is to Consume the WCF Created in .NET 4.5 in Visual COBOL.(In Native Code VIA Managed Code)

To Do this I have followed following Steps:

1. Created an Managed Project in Visual COBOL, Added the Service Reference of .NET WCF. 

2. Selected the Property of Managed project as "Register for COM Interop". I am getting couple of Warning for the same. (Type Library exporter warning Generic Code may not exported to COM.)

3. Created an managed program to create an object of WCF Client Class and call the WCF methods.

3. Created an Native Project and added a Native Program.

4. Provide the Class Control section to point to the OLE object created by Managed Project.

5. Tried to Invoke the Managed Program of Managed Project from Native Program.

I am able to reach to the Managed Program (getting a display from there) But when managed program tries to call the WCF method , I am getting following error " Could not find the default endpoint element that references the contract "IService1". in the service model Client Configuration Section.

this might be because no configuration file was found for your application , or because no endpoint element matching this contract could be found in the client element".

Hope you are able to understand the problem, Let me know if you require any additional info. 

Let us know what can be possible problem in this approach.

Regards,

Charan

Parents
  • Because the project which is calling the WCF service is a Class library so that it can be registered for COM it does not pick up the app.config file which is generated by adding the service reference. Only main programs read and use app.config so it is ignored.

    To get around this you can set the endpoint parameters dynamically within the COM program when it instantiates the service:

    Example:

           class-id WcfCOMTest.Class1.
           
           working-storage section.
           method-id callWCFTest.
           local-storage section.
           01 wcfservice type ServiceReference1.Service1Client.
           01 remoteAddress type System.ServiceModel.EndpointAddress value new System.ServiceModel.EndpointAddress("localhost:62048/Service1.svc").
                 
           procedure division using by value theValue as binary-long
                              returning theString as string.
    
               set wcfservice to new ServiceReference1.Service1Client(new type System.ServiceModel.BasicHttpBinding(), remoteAddress)
               set theString to wcfservice::GetData(theValue)
               
               goback.
           end method.
    
Reply
  • Because the project which is calling the WCF service is a Class library so that it can be registered for COM it does not pick up the app.config file which is generated by adding the service reference. Only main programs read and use app.config so it is ignored.

    To get around this you can set the endpoint parameters dynamically within the COM program when it instantiates the service:

    Example:

           class-id WcfCOMTest.Class1.
           
           working-storage section.
           method-id callWCFTest.
           local-storage section.
           01 wcfservice type ServiceReference1.Service1Client.
           01 remoteAddress type System.ServiceModel.EndpointAddress value new System.ServiceModel.EndpointAddress("localhost:62048/Service1.svc").
                 
           procedure division using by value theValue as binary-long
                              returning theString as string.
    
               set wcfservice to new ServiceReference1.Service1Client(new type System.ServiceModel.BasicHttpBinding(), remoteAddress)
               set theString to wcfservice::GetData(theValue)
               
               goback.
           end method.
    
Children
No Data