none
Adding a Service Reference doesn't add client, just interface RRS feed

  • Question

  • Hello, I'm getting my feet wet with WCF. I followed this video https://www.youtube.com/watch?v=GzN1vHWlJjA to create a basic WCF service and it worked well. But when trying to create a new very basic service I can't figure out why it doesn't generate a client after adding the service reference.

    This is my basic service interface:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace eFileService1
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IeFileService" in both code and config file together.
        [ServiceContract]
        public interface IeFileService
        {
            [OperationContract]
            Int32 CreateFiling();
        }
    }


    This is my service implementation:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace eFileService1
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "eFileService" in code, svc and config file together.
        // NOTE: In order to launch WCF Test Client for testing this service, please select eFileService.svc or eFileService.svc.cs at the Solution Explorer and start debugging.
        public class eFileService : IeFileService
        {
            public Int32 CreateFiling()
            {
                Int32 nRtnVal = 0;
                return nRtnVal;
            }
        }
    }
    

    This is how my referenced service looks in object browser

    As you can see I don't have a eFileServiceClient what I have is IeFileServiceClient. I can't see what can be wrong that is not giving me a client.

    Thank you for your help

    LG


    Luis

    Wednesday, December 17, 2014 2:41 PM

Answers

  • eFileService is a namespace. The main issue is that your names don't follow the naming convention. If you rename your interface to IFileService and your service implementation to FileService and then remove the service reference and add a new one it should work as your expect. There is a proxy created in the namespace that you choose when adding the service reference.

    Please remember to mark helpful posts as answer and/or helpful.

    Wednesday, December 17, 2014 4:25 PM
  • Hi,

    For this scenario, within the video, it creates a WCF service project which is hosted in IIS/WAS. Then create a windows form application as the client side and add the service reference for the service, and call the method within the service.

    >>But trying to rename the IService1.svc, Service1.cs and/or the interface to a more meaningful name makes the service reference to give me a namespace instead of a client object.

    It’s recommended that you could create a new service within the project and then rebuild the service and published it to the IIS, finally add service reference within the client side project.

    Regards

    Friday, December 19, 2014 7:51 AM
    Moderator
  • Hi,

    Based on your description, it seems that all the operations are fine. After you add the new service reference, it shows as IeFileServiceClient, which actually is a class. However, when you try to create the object of the class, it does not show the class, for this situation, it seems that you don't add the service reference in your code behind.

    using TestFileService.eFileService1;

    Then, you could use the class within the TestFileService.eFileService1 namespace.

    Regards

    Wednesday, December 24, 2014 3:23 AM
    Moderator

All replies

  • IeFileServiceClient is indeed a class, you can see that on the icon in the object browser. This will create an instance of it:

    TestFileService.eFileService1.IeFileServiceClient client = new TestFileService.eFileService1.IeFileServiceClient("yourEndPoint");

    The name "IeFileServiceClient" may be a bit confusing though, but you could just double click on the class in the object browser and then change its name by right-clicking on the class name in the code editor and choose "Refractor->Rename".

    Please remember to mark helpful posts as answer and/or helpful and please start a new thread if you have a new question.

    Wednesday, December 17, 2014 3:38 PM
  • Hi Magnus, thank you for taking the time, but there's not refactor on the right click and more important I cannot instantiate a client from IeFileServiveClient intellisense shows it as a namespace. 

    

    The service from the video shows both the namespace and the class, see below in second picture,

    as soon as I type "Math" 

    Thank you for your help


    Luis

    Wednesday, December 17, 2014 4:17 PM
  • eFileService is a namespace. The main issue is that your names don't follow the naming convention. If you rename your interface to IFileService and your service implementation to FileService and then remove the service reference and add a new one it should work as your expect. There is a proxy created in the namespace that you choose when adding the service reference.

    Please remember to mark helpful posts as answer and/or helpful.

    Wednesday, December 17, 2014 4:25 PM
  • Thank you very much Magnus, I understand what you are describing, and I have made sure that the names don't conflict, I even try totally different names for the class, the interface and the implementation to no avail. This is what I did

    1 - I created a new WCF Application project

    2 - Tested the application "as is" by using "Add service reference" and everything I expected was there

    3 - Added a new WCF Service to the project, deleted the original Service1 and IService1 files, publish again without adding anything to the generated code.

    4 - Updated the "Service Reference" and tested the application "as is" --> problem appeared

    If I do step 1 and 2 and add my classes to the generated code I can see my objects the way I expect. But trying to rename the IService1.svc, Service1.cs and/or the interface to a more meaningful name makes the service reference to give me a namespace instead of a client object. I don't understand, the sample from the video works and I'm doing the same, or so I believe :-)

    Thank you


    Luis

    Wednesday, December 17, 2014 7:47 PM
  • Hi,

    For this scenario, within the video, it creates a WCF service project which is hosted in IIS/WAS. Then create a windows form application as the client side and add the service reference for the service, and call the method within the service.

    >>But trying to rename the IService1.svc, Service1.cs and/or the interface to a more meaningful name makes the service reference to give me a namespace instead of a client object.

    It’s recommended that you could create a new service within the project and then rebuild the service and published it to the IIS, finally add service reference within the client side project.

    Regards

    Friday, December 19, 2014 7:51 AM
    Moderator
  • Hi Shawn, thank you for taking the time to answer. Yes I understand the service is hosted in IIS, mine is also hosted in IIS. I did exactly what you described, I created a WCF application, published it to IIS, tested the functionality, added new WCF service, rebuild and publish to IIS, tested new service--->same problem.

    Thank you for your help.

    LG


    Luis

    Saturday, December 20, 2014 2:00 PM
  • Hi,

    Based on your description, it seems that all the operations are fine. After you add the new service reference, it shows as IeFileServiceClient, which actually is a class. However, when you try to create the object of the class, it does not show the class, for this situation, it seems that you don't add the service reference in your code behind.

    using TestFileService.eFileService1;

    Then, you could use the class within the TestFileService.eFileService1 namespace.

    Regards

    Wednesday, December 24, 2014 3:23 AM
    Moderator