0

I googled for 2 days and tried almost everything, but I still can't get this stuff working.

I have 2 WCF services. I use self-hosting, not IIS(for some reasons IIS isn't working for me). One is duplex, another is standart. Here are their contracts: Duplex:

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IServiceCallback))]
public interface IClientService
{
    [OperationContract(IsOneWay = true)]
    void SolveTask(string pipelineName, string data);

    [OperationContract(IsOneWay = true)]
    void GenerateTask(List<GeneratorMethod> parameters);

    [OperationContract]
    bool Ping();
}

public interface IServiceCallback
{

    [OperationContract(IsOneWay = true)]
    void SendResult(SampleAnswer[] answers);

    [OperationContract(IsOneWay = true)]
    void RequestGeneratorParameters();

    [OperationContract(IsOneWay = true)]
    void SendGenerationResult(string text);
}

Classic:

[ServiceContract]    
public interface IServerManagementService
{
    [OperationContract]
    [FaultContract(typeof(XmlError))]
    [FaultContract(typeof(UnknownError))]
    [FaultContract(typeof(InitializationError))]
    void InitializeServer();

    [OperationContract]
    void StartServer();

    [OperationContract]
    void StopServer();

    [OperationContract]
    void RestartServer();
}

I have following config:

<configuration>

<services>

  <service behaviorConfiguration="Service" name="LinProgWebServer.ClientService">
    <endpoint address="net.tcp://localhost:8078/LinProgWebServer/ClientService"
      binding="netTcpBinding" bindingConfiguration="netTcpEventBinding"
      contract="LinProgWebServer.IClientService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService" />
      </baseAddresses>
    </host>
  </service>
  <!--сервис управления сервером-->
  <!--<service behaviorConfiguration="Service" name="LinProgWebServer.ServerManagementService">
    <endpoint address="net.tcp://localhost:8079/LinProgWebServer/ManagementService"
      binding="netTcpBinding" bindingConfiguration="netTcpEventBinding"
      contract="LinProgWebServer.IServerManagementService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/LinProgWebServer/ManagementService" />
      </baseAddresses>
    </host>
  </service>-->

</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="Service">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Now i have a big trouble: I CAN find classic service via add service reference and CANNOT find duplex service. I tried netstat and it says that both services are listening on their ports. What am i doing wrong?

Here is exception i get:

    There was an error downloading   'http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 405: Method Not Allowed.
Metadata contains a reference that cannot be resolved: 'http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService'.
There was no endpoint listening at http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.

I'll be grateful for any help.

Alex Voskresenskiy
  • 2,143
  • 2
  • 20
  • 29

4 Answers4

0

Make sure you .svc file has the correct name of the class you added in your Service Reference

if you added a service called 'Foo' it should look like:

<%@ ServiceHost Language="C#" Debug="true" Service="Foo" CodeBehind="Foo.svc.cs" %

Also, make sure you have In your web.config

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
0

I'm not sure whether this is going to be usefull. All my configs and services were fine, but i had a mistace in types, which were involved in work of wcf services, i haven't marked one of the types as datacontract. U'm very surprised why service started without erros and showed me such not informative messages. Also, thanks Yuval for reminding about InstanceContextMode attribute.

Alex Voskresenskiy
  • 2,143
  • 2
  • 20
  • 29
0

Add this to the area where you setup you set up your endpoint and reference your service classes:

//config service metadata
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;


   ServiceMetadataBehavior mb = new ServiceMetadataBehavior();
   ServiceHost.Description.Behaviors.Add(mb);

   if (bUseSSL) {
        mb.HttpsGetEnabled = true;
        mb.HttpGetEnabled = false;
        ServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
    } else {
        mb.HttpsGetEnabled = false;
        mb.HttpGetEnabled = true;
        ServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
    }
Brian
  • 3,653
  • 1
  • 22
  • 33
0

You should not be using the same URL that you were using to host it in the dev environment. Localhost means nothing outside of the machine, anyway. Use the IP address of the machine and also -- you might have to use netsh to open the port on that machine.

jinzai
  • 436
  • 3
  • 9