WCF service called from a VB.net project and a C# project RRS feed

  • Question

  • User-1575141290 posted

    Hello everyone,

    The following code is an extract from a working VB.net project that connects to an established WCF service

    ' Start a call to the Middleware service
    ' "Middleware" is the Namespace given when adding the reference Dim M As New Middleware.CustomerIdentificationServiceClient ' Create a new Customer class to hold the result Dim Customer As New Middleware.Customer ' Call the service Customer = M.GetCustomerInformation("123456") 'Customer Number

    I now need to do a similar task but from a C# project, and I'm getting convert errors in Visual Studio. I initially tried an online service to convert the VB to C but with little success. I've looked a lot into this online but can't find the answer, maybe not searching for the right things?

    Using Middleware;

    // Start a call to the Middleware service // Reference are not qualified as Using above pulls them in. CustomerIdentificationServiceClient M = new CustomerIdentificationServiceClient(); // Create a new UKSL Agreement reference to hold the result Customer C = new Customer(); C = M.GetCustomerInformation("123456"); //The customer number

    No matter what I try in the C# project I get the following error (highlighted against the last line in the C# code):

    Cannot implicitly convert type 'MyProject.Middleware.Customer' to 'MyProject.Middleware.Customer [C:\Path\To\Code\MyProject\Project\MyProject\Service References\Middleware\Reference.cs(20)]' C:\Path\To\Code\MyProject\Project\MyProject\BLL\AuthorisationInformation.cs 48 20 MyProject

    Really appreciate any thoughts on this.

    A few extra notes, I've clearly changed some name/references in the code, but I believe the fundamental points still stand. Secondly C# is not my strong point at all, but very comfortable with VB.Net. 



    Tuesday, July 8, 2014 6:39 AM


All replies

  • User-1353043493 posted


    try like this

    C = (Customer)M.GetCustomerInformation("123456");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 6:49 AM
  • User-1575141290 posted

    Excellent, the compiler isn't complaining any more, haven't got enough code done to actually attempt to run it - but we are looking good!

    Thanks very much for the direction. 

    Tuesday, July 8, 2014 9:07 AM