2

I added the following service configuration to allow my method to be called via Ajax.

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="webHttpBehavior">
                <webHttp />
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <webHttpBinding>
            <binding name="webHttpXDomain" crossDomainScriptAccessEnabled="true" />
        </webHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="ServiceBehavior" name="My.Service.AccountService">
            <endpoint address="" behaviorConfiguration="webHttpBehavior"
                binding="webHttpBinding" bindingConfiguration="webHttpXDomain"
                name="Scripting" contract="My.Service.ServiceContracts.IAccountService" />
        </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

But now when I try to use WCF Test Client or run my unit tests it says no endpoint listening or comes up with nothing. The ajax client is working fine.

ryan
  • 6,541
  • 5
  • 43
  • 68
  • Try deleting your service reference and then add it back again. – Tad Donaghe Dec 05 '11 at 13:28
  • This looks like a fairly complete section of the config file. What did it look like before your edits? – Merlyn Morgan-Graham Dec 05 '11 at 13:34
  • Deleting/adding again does not help. Before edits it was stock. .NET 4 doesn't make you specify anything for service endpoints. Using default web.config unit tests/generated proxy worked – ryan Dec 05 '11 at 13:45
  • Turns out this is the answer I was looking for: http://stackoverflow.com/questions/186631/rest-soap-endpoints-for-a-wcf-service/186695#186695 – ryan Dec 09 '11 at 15:24

4 Answers4

3

First of all REST don't expose metadata .So I don't think you can call like this.

Second, for unit testing is it really required to call like a client calls? Why can't you try testing your server side alone by creating unit test project?

We are in same scenario as our project uses Azure and Mobile client and successfully unit testing with VS test project.

For load testing yes..we need to simulate the call from clients.

Joy George Kunjikkuru
  • 1,495
  • 13
  • 27
  • I don't feel its an accurate test without using a client just as my subscribers would. Maybe that's just me – ryan Dec 13 '11 at 19:20
  • For the real scenario you can use the web test available in VSTS2010. It just records the url requests and you can play it later by creating more number of virtual uses. – Joy George Kunjikkuru Dec 13 '11 at 19:27
1

The issue here is that the webHttpBinding is not a SOAP binding. It really is designed for REST services and there is no way to for the webHttpBinding to expose the metadata by default (this explains the WCF Test Client issues).

You can find a more complete answer here regarding webHttpBindings: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/deabd25b-a219-4e95-9826-d40dc2f75543

As for unit testing (though it sounds more like an integration test to me), you need to have a specific setup for your test methods:

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("%PathToWebRoot%\\VSProjects", "/VSProjects")]
[UrlToTest("http://localhost/VSProjects")]
public void MethodToTest()
{
}

More info: http://msdn.microsoft.com/en-us/library/ms243399.aspx

Gary.S
  • 7,076
  • 1
  • 26
  • 36
0

See the following link for your test setup. Especially the last point in the article.

Get this wrong and you will get the following error:

System.InvalidOperationException : Service ‘Test.SomeDir.FooService’ has zero application (non-infrastructure) endpoints.

2. Note the end point address ‘abc’.

1
<endpoint address="abc"
This need to map to the path the immediately follows the base host address in your URL;

http://localhost:1980/abc

Hope this helps. I find writing a test like this useful for testing my end points and making sure I’ve got everything setup.
coolcake
  • 2,917
  • 8
  • 42
  • 57
0

I have added an additonal endpoint to publish the soap metadata required by the WCF test client and the unit tests.

The setup and a similar question is described at REST / SOAP endpoints for a WCF service

Community
  • 1
  • 1
ryan
  • 6,541
  • 5
  • 43
  • 68