Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting WCF service inside web project

Tags:

.net

wcf

I'm trying to create a wcf service inside a c# mvc web project. I've added a new item of type "WCF Service" and added a test method in the provided Interface:

[ServiceContract]
public interface ITest
{
    [OperationContract]
    void DoWork();

    bool testWorking();
}

And the provided service:

public class Test : ITest
{
    public void DoWork()
    {
    }

    public bool testWorking()
    {
        return true;
    }
}

And I've then gone over to the web.config file and added the following to the system.ServiceModel tag:

 <services>
      <service name="Test" behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="" binding="wsHttpBinding" contract="ITest">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex"  binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors" >
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

At this point, as I understand it, I should be able to view this in a browser and get a test message telling me that it's about time I implemented a client to use this service. However what actually happens is that my browser downloads the .svc file!

Two questions:

1) What the hell am I doing wrong? Why am I not seeing the expected message?

2) Is there any way I can automatically start the WCF testing tool to run on this service? The only guidelines I can find are for starting from a WCF project.

Update: (content of svc file - grabbed from comment)

<%@ ServiceHost Language="C#" Debug="true" 
    Service="myemployersaddress.com.Test" CodeBehind="Test.svc.cs" %> 
like image 918
Bob Tway Avatar asked Nov 15 '22 02:11

Bob Tway


1 Answers

From what you've described you should be fine, but since you're not:

  1. What server are you using? IIS, cassini?
  2. What is the contents of the svc file that you download? (open it in notepad)

To start the test tool from inside visual studio, right click on the .svc file and 'set as start page' and then hit f5. That should open the test tool and allow you to inspect your service. That should give you some clues as to what the problem is.

like image 157
ilivewithian Avatar answered Dec 24 '22 05:12

ilivewithian