locked
How to Consume this WCF Service? RRS feed

  • Question

  • User231929733 posted

    i have created a wcf service but i have used 3 projects for it; 
    1) ServiceLibrary (WCF library) 
    2) Web 
    3) ConsoleTestClient 
    my servicelibrary app.config file looks like this;

    <system.serviceModel>
        <services>
          <service name="MrDAStoreJobs.ServiceLibrary.AdvertisementService">
            <clear />
            <endpoint address="basic"
                      binding="basicHttpBinding" bindingConfiguration=""
                      contract="MrDAStoreJobs.ServiceLibrary.Interface.IAdvertisementService" />
            <endpoint name="mexHttpBinding"
              contract="IMetadataExchange"
              binding="mexHttpBinding"
              address="mex" />
    
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:13758/" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information,
              set the value below to false before deployment -->
              <serviceMetadata httpGetEnabled="True" />
              <!-- To receive exception details in faults for debugging purposes,
              set the value below to true.  Set to false before deployment
              to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel> <br />

    Now, to host this library, i have done the following settings in my web.config file of the web Project. 

    The svc file name is  WcfDataService1

    public class WcfDataService1 : DataService<AdvertisementService>
        {
            // This method is called only once to initialize service-wide policies.
            public static void InitializeService(DataServiceConfiguration config)
            {
                config.UseVerboseErrors = true;
    ServiceOperationRights.All);
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
            }
        }
      <system.serviceModel>
        <services>
          <service name="MrDAStoreJobs.ServiceLibrary.AdvertisementService">
            <clear />
            <endpoint address="basic" 
                      binding="basicHttpBinding" bindingConfiguration="" 
                      contract="MrDAStoreJobs.ServiceLibrary.Interface.IAdvertisementService" />
            <endpoint name="mexHttpBinding"
              contract="IMetadataExchange"
              binding="mexHttpBinding"
              address="mex" />
    
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:13758/WcfDataService1.svc" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, 
              set the value below to false before deployment -->
              <serviceMetadata httpGetEnabled="True" />
              <!-- To receive exception details in faults for debugging purposes, 
              set the value below to true.  Set to false before deployment 
              to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    Now, when i test this service using directly (ServiceLibrary project) using WCF test client, i see the following and works everything great;

    The issue is when i try to run my Web

     project(which i use as a host for wcf service). And then go to the console test client and want to add reference using add reference. I don't see my Get and SET methods (like test client)

    Why i don't see my IAdvertisementService interface and the methods 
    Do i have to deploy this to actuall IIS?


    Wednesday, March 6, 2013 12:59 PM

All replies

  • User220959680 posted

    Now, to host this library, i have done the following settings in my web.config file of the web Project. 

    It is not required to update Web project configuration, adding service reference to the project creates a proxy class and updates the client side configuration (Web.config or App.config).

    Delete the service configuration that is <ServiceModel> element from the Web project configuration, then choose Add service reference.

    please update the thread as you progress.

    Wednesday, March 6, 2013 5:47 PM
  • User231929733 posted

    But the web project is the host for Wcf. i think we have to use add reference in a client (in my case console project). Correct me if i am wrong

    Thursday, March 7, 2013 1:12 AM
  • User231929733 posted

    i have already tried apress, wrox and packtpub books 

    Thursday, March 7, 2013 1:24 AM
  • User220959680 posted

    But the web project is the host for Wcf. i think we have to use add reference in a client (in my case console project). Correct me if i am wrong

    Add Service Reference is the correct context menu to add service reference. 

    To elaborate further:-


    1) WCF service library (from the source provided it is evident that it is WCF Data service) , which is a type of class library project.

    2) Web application is hosting the above WCF service library project

    3) console application is  the service client that consumes the service

    <service name="MrDAStoreJobs.ServiceLibrary.AdvertisementService">
           
    <clear />
           
    <endpoint address="basic"
                      binding
    ="basicHttpBinding" bindingConfiguration=""
                      contract
    ="MrDAStoreJobs.ServiceLibrary.Interface.IAdvertisementService" />
           
    <endpoint name="mexHttpBinding"
              contract
    ="IMetadataExchange"
              binding
    ="mexHttpBinding"
              address
    ="mex" />

    In the above configuration there are two service end points, exposing the service i.e., 

    1) BasicHttpBinding:- Service end point

    2)   mexHttpBinding: This endpoint is called a MEX endpoint, from Metadata EXchange to expose metadata.


    Service end point http://localhost:13758/mex is the metadata end point.

    To access the service from console application choose Add Service Reference context menu and enter 

    http://localhost:13758/WcfDataService1.svc?wsdl

    Please update this thread as you progress.

    Thursday, March 7, 2013 6:45 AM
  • User220959680 posted

    Hello

    Above suggested works during your development/testing with in Visual Studio. In production environment to become active, a service must be hosted within a run-time environment that creates it and controls its context and lifetime. Windows Communication Foundation (WCF) services are designed to run in any Windows process that supports managed code.

    There are number of hosting options http://msdn.microsoft.com/en-GB/library/ms730158.aspx

    Hosting the service IIS is typical.   Hosting in IIS is quite similar to hosting any ASP.NET web applicaiton. Here is the video tutorial.

    Here is good intro article on WCF 

    Thursday, March 7, 2013 7:08 AM
  • User231929733 posted

    @sukumarraju thanks for you time and reply.

    Now, i have deleted my WcfDataService.svc file and i have modified my configuaration to use WAS just like below and it works when i type 

    http://localhost:13758/WcfDataService1.svc

      <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
          <serviceActivations>
            <add relativeAddress="WcfDataService1.svc" service="MrDAStoreJobs.ServiceLibrary.AdvertisementService" />
          </serviceActivations>
          </serviceHostingEnvironment>
        <services>
          <service name="MrDAStoreJobs.ServiceLibrary.AdvertisementService">
            <clear />
            <endpoint address="basic" 
                      binding="basicHttpBinding" bindingConfiguration="" 
                      contract="MrDAStoreJobs.ServiceLibrary.Interface.IAdvertisementService" />
            <endpoint name="mexHttpBinding"
              contract="IMetadataExchange"
              binding="mexHttpBinding"
              address="mex" />
    
            <!--<host>
              <baseAddresses>
                <add baseAddress="http://localhost:13758/WcfDataService1.svc" />
              </baseAddresses>
            </host>-->
          </service>
        </services>
        <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>-->
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, 
              set the value below to false before deployment -->
              <serviceMetadata httpGetEnabled="True" />
              <!-- To receive exception details in faults for debugging purposes, 
              set the value below to true.  Set to false before deployment 
              to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    

    However, my basic end point and mex aren't working and by the way the hosting project is of type Asp.Net MVC 4

    Thursday, March 7, 2013 11:01 AM