views:

157

answers:

2

I have a very simple hello world WCF service as given below. When i call it via asp.net project by adding web service reference it works perfectly fine. But when i called it using JQury or standard js ajax call (using XMLHttpRequest) it calls back the success function but returns null data.

When i tried to access it via firefox browser using this address "http://localhost:8282/Test/TestService.svc/HelloWorld"

it returned an error with code "a:ActionNotSupported" and error detail as "The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."

if i change binding to "wsHttpBinding" then it returns nothing even in the firefox browser

here is the code:

file "Test/ITestService.svc"

[ServiceContract(Namespace = "http://localhost:8282/")]
public interface ITestService
{

    [OperationContract]
    string HelloWorld();
}

file "Test/TestService.svc"

public class TestService : ITestService
{
    public string HelloWorld()
    {
        return "This is echo from server. Hello World";
    }
}

file "web.config"

"

<services>
<service name="radMLRPC.Test.TestService" behaviorConfiguration="radMLRPC.Test.TestServiceBehavior"
    <endpoint address="HelloWorld" binding="webHttpBinding" contract="radMLRPC.Test.ITestService">
        <identity>
        <dns value="localhost"/>
        </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
</services>
<behaviors>
<serviceBehaviors>
    <behavior name="radMLRPC.Test.TestServiceBehavior">
    <serviceMetadata httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
    </serviceBehaviors>
</behaviors>

"

+1  A: 

with code above service only allows soap requests so to allow Get http requests we have to modify code as given below:

In interface:

    [WebGet(UriTemplate="helloworld")]
    [OperationContract]
    string HelloWorld();

in web config:

  • add behaviorConfiguration:

    <endpoint address="" binding="webHttpBinding" contract="radMLRPC.Test.ITestService" behaviorConfiguration="webBehav">
    
  • then in behaviors add following tag:

    < endpointBehaviors > < behavior name="webBehav" > < webHttp /> < /behavior > < /endpointBehaviors >

"please remove extra spaces from above. it was not showing the tags without extra spaces"


Check out some resources for that:

An Introduction To RESTful Services With WCF http: //msdn.microsoft.com/en-us/magazine/dd315413.aspx

Endpoint.TV screencasts:

Endpoint.TV in general has really good coverage for WCF and WCF REST stuff. http: //channel9.msdn.com/shows/Endpoint/

Adeem
A: 

Consuming ASP.net WebServices, WCF Services and static Page methods from JavaScript (sans MS AJAX)

For webHttp and client script, a mex binding is not useful. drop it for now.

The identity may be causing you some grief, drop it for now.

You have HelloWorld as your address, in order to call the HelloWorld method on your service you would need to call http://localhost:8282/Test/TestService.svc/HelloWorld/HelloWorld. drop it.

<services>
    <service name="radMLRPC.Test.TestService" behaviorConfiguration="radMLRPC.Test.TestServiceBehavior"
    <endpoint address="" binding="webHttpBinding" contract="radMLRPC.Test.ITestService"/>
  </service>
</services>
<behaviors>
    <serviceBehaviors>
    <behavior name="radMLRPC.Test.TestServiceBehavior">
    <serviceMetadata httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Now that may not get you all the way there but will give us a better starting point. I am willing to help you resolve this.

Compare what we have now with the working example shown in the linked article

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="AjaxEndpointBehavior">
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="ClientScriptServices.Service1Behavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="ClientScriptServices.Service1Behavior" name="ClientScriptServices.Service1">
      <endpoint behaviorConfiguration="AjaxEndpointBehavior" binding="webHttpBinding" contract="ClientScriptServices.Service1" />
    </service>
  </services>
</system.serviceModel> 

And see if we can get your config shaped similarly and we can cover some finer points of tuning your input and output formats.

Sky Sanders
You seem to be mistaken. The link gives clear guidance on performing what you would like to do. There are a few things wrong with the configuration that you show, perhaps we can work on that. see edited answer
Sky Sanders
i could not solve my problem without <webHttp/> cause i am not using dotnet scriptmanager for client instead its simple html application without any server technology and for that i need my service to expose its methods to http web. Please let me know if i am mistaken
Adeem