none
WCF service is not visible if I put source code in directory inside the project dir RRS feed

  • Question

  • I have a strange problem with hosting my WCF service as Windows Service.

    I’ve made 2 examples:

    1. Easy one

    I wrote WCF service (SecurityService) and put it in the project directory. The namespace is ServiceLibrary.

    Config for such service:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <system.web>
        <compilation debug="true" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name="ServiceLibrary.SecurityService">
            <host>
              <baseAddresses>
                <add baseAddress = "http://localhost:9000/SecurityService" />
              </baseAddresses>
            </host>
            <endpoint address ="" binding="wsHttpBinding" contract="ServiceLibrary.ISecurityService">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="True"/>
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    
    </configuration>

     

    That example works perfect.

    1. I complicated a lil bit (or just customized, putting services and contracts in special directories, and the service is inaccessible after build, deployment and  instalation as a windows service.

    Directory tree:

    Project dir -> SysSecurity -> Imp -> SecurityService.cs

    Project dir -> SysSecurity -> Contracts -> ISecurityService.cs

    The namespaces have the names of directories.

    I fixed names in config:

    <service name="ServiceLibrary.SysSecurity.Impl.SecurityService">

     <endpoint address ="" binding="wsHttpBinding" contract="ServiceLibrary.SysSecurity.Contracts.ISecurityService">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
    • Edited by dzaak Tuesday, May 21, 2013 6:35 PM
    Tuesday, May 21, 2013 6:33 PM

All replies

  • And exception while connecting with service using wcftestclinet:

    Error: Cannot obtain Metadata from http://localhost:9000/SecurityService/mex If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://localhost:9000/SecurityService/mex    Metadane zawierajĄ odwoˆanie, kt˘rego nie moľna rozpozna†: "http://localhost:9000/SecurityService/mex".    W elemencie http://localhost:9000/SecurityService/mex brak nasˆuchujĄcego punktu koäcowego, kt˘ry m˘gˆby odebra† komunikat. Jest to cz©sto spowodowane niepoprawnym adresem lub akcjĄ protokoˆu SOAP. Sprawd« wˆa˜ciwo˜† InnerException (je˜li jest obecna), aby uzyska† wi©cej szczeg˘ˆowych informacji.    Nie moľna poˆĄczy† si© z serwerem zdalnym    Nie moľna nawiĄza† poˆĄczenia, poniewaľ komputer docelowy aktywnie go odmawia 127.0.0.1:9000HTTP GET Error    URI: http://localhost:9000/SecurityService/mex    Podczas pobierania "http://localhost:9000/SecurityService/mex" wystĄpiˆ bˆĄd.    Nie moľna poˆĄczy† si© z serwerem zdalnym    Nie moľna nawiĄza† poˆĄczenia, poniewaľ komputer docelowy aktywnie go odmawia 127.0.0.1:9000

    Everything is ok with mex, because im using almost the same config and the same services when I store source code just in project directory. So that why I think service cannot be found by web/wcftestclient.


    • Edited by dzaak Tuesday, May 21, 2013 6:40 PM
    Tuesday, May 21, 2013 6:38 PM
  • Hi,

    It seems the issues are resolved by yourself, if not, what is the issue now?

    If you make changes to the service, you must first stop it and uninstall it, then re-install the service at Service Control Manager. To check if you have properly expose metadata, you can view the service at browser when start the service at Service Control Manager(e.g http://localhost:8000/ServiceModelSamples/service).

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 22, 2013 9:46 AM
    Moderator
  • Its not solved yet. I tried to host my service via Host from Visual Studio (WcfSvcHost)

    First example runs and works.

    Second example has error after Host tried to run it:

    ystem.InvalidOperationException: Nazwa kontraktu „ServiceLibrary.SysSecurity.Contracts.ISecurityService” nie została odnaleziona na liście kontraktów zaimplementowanych przez usługę „SecurityService”.
       w System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName)
       w System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
       w System.ServiceModel.ServiceHostBase.ApplyConfiguration()
       w System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
       w System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
       w Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
       w Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)

    In english, "the contract named ServiceLibrary.SysSecurity.Contracts.ISecurityService was not found on the list of contracts implemented by the SecurityService service".

    But the files are the same like listed below:

    Config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <system.web>
        <compilation debug="true" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name="ServiceLibrary.SysSecurity.Impl.SecurityService">
            <host>
              <baseAddresses>
                <add baseAddress = "http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary1d/Service1/" />
              </baseAddresses>
            </host>
            <endpoint address ="" binding="wsHttpBinding" contract="ServiceLibrary.SysSecurity.Contracts.ISecurityService">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="True"/>
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    
    </configuration>
    

    Contract:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ServiceLibrary.SysSecurity.Messages;
    using System.ServiceModel;
    
    namespace ServiceLibrary.SysSecurity.Contracts
    {
        [ServiceContract]
        public interface ISecurityService
        {
            [OperationContract]
            GetAllSystemUsersResponse GetAllSystemUsers(GetAllSystemUsersRequest request);
            
        }
    }
    

    Service:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ServiceLibrary.SysSecurity.Messages;
    //using DatabaseDriver;
    using ServiceLibrary.SysSecurity.Contracts;
    //using Facade;
    
    namespace ServiceLibrary.SysSecurity.Impl
    {
        public class SecurityService : ISecurityService
        {
    
            public GetAllSystemUsersResponse GetAllSystemUsers(GetAllSystemUsersRequest request)
            {
                GetAllSystemUsersResponse response = new GetAllSystemUsersResponse();
    
                try
                {
                    ConnectToDatabase();
                }
                catch (Exception exc)
                {
                    response.AddErrorMessage(exc.Message, exc.StackTrace, exc.GetType().ToString());
                }
    
                return response;
            }
            private void ConnectToDatabase()
            {
    
            }
        }
    }
    

    Wednesday, May 22, 2013 5:20 PM
  • Found out, that the problem happens, when the service is in the dirrerent directory that contract.

    Still looking for a fix.

    Saturday, May 25, 2013 3:32 PM
  • Hi,

    If you mean the service class is located at another project, you need reference that project( right click Add Reference, at the Project tab find the project, click Add), you can refer the screenshot below for an example.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 27, 2013 2:03 AM
    Moderator
  • I know about the reference, its added of course. Ive tested a lil bit and noticed, that problem occurs when I have complex directory structure inside the service library project.

    1. root (project dir)

    1.1. child1

    1.1.1 impl (services in that dir)

    1.1.2 contract (contracts in that dir)

    Project compiles, but the runtime error is thrown.

    You can test it using files i mentioned above + conf.

    Try dir name the same as fragments of namespace in every file.

    I used temporaty resolution and removed level 1.1. (child1 - SysSecurity from example). Just keep my files in 1.1 Impl and 1.2 Contracts. 

    • Edited by dzaak Tuesday, May 28, 2013 5:48 PM
    Tuesday, May 28, 2013 5:45 PM