Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1068615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:18:37+00:00 2026-05-16T20:18:37+00:00

I’m trying to call an wcf self hosted method from jquery but, i’m aways

  • 0

I’m trying to call an wcf self hosted method from jquery but, i’m aways getting the message: “method not allowed”. I found some answers to this issue on this forum but nothing worked to me….
ps. It works fine when I add the reference on a console app and consume it.

it’s an windows forms self-hosted app

form load:

ServiceHost host = new ServiceHost(typeof(MyServices), new Uri[] { });
host.Open();

App.Config

<system.serviceModel>
        <services>
            <service behaviorConfiguration="ServiceConfig" name="MyServices">
                <endpoint address="srv" binding="basicHttpBinding" contract="Operations" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8766" />
                    </baseAddresses>
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceConfig">
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    </system.serviceModel>

Operation Contract:

[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string Test();

Service:

public string Test()
{
return "Good!";
}

JQuery

$.ajax({
    url: "http://localhost:8766/Test",
    contentType: "application/json",
    processData: false,
    //data: '{}', // tried passing data
    type: "GET", // tried POST and pass nothing(deleting this param), but nothing...
    success: function (msg) {
        console.log(msg);
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:18:38+00:00Added an answer on May 16, 2026 at 8:18 pm

    Well, your current problem is caused by the fact that WebInvoke, when you don’t specify the Method parameter, will default to “POST”. Your jQuery code is issuing a “GET” request, so the “method not allowed” error would be expected.

    However, your comment about trying GET initially and getting nothing in return makes me lean towards your problem being a violation of the same origin policy with your browser. Since you’re hosting the service in a Windows Form with the address of http://localhost:8766, I’m assuming your web site is not located at `http://localhost:8766‘. Per the same origin policy:

    The term “origin” is defined using the
    domain name, application layer
    protocol, and (in most browsers) TCP
    port of the HTML document running the
    script. Two resources are considered
    to be of the same origin if and only
    if all these values are exactly the
    same.

    If you’re returning data from your service in JSON format, you may want to consider using a GET request that returns JSONP. This type of request does not violate the same origin policy as requesting remote scripts are allowed. Your jQuery call would then look like this:

    $.ajax({
        url: "http://localhost:8766/Test",
        dataType: "jsonp",
        processData: false,
        type: "GET",
        success: function (msg) {
            console.log(msg);
        }
    });
    

    Since you’re using WebInvoke, you may also want to use the WebHttpBinding binding instead of BasicHttpBinding. WebInvoke doesn’t work unless it’s used with WebHttpBinding. And when you use WebHttpBinding, you can customize it so that it responds to JSONP requests. So your config would look like this:

    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
            </webHttpBinding>
        </bindings>
        <behaviors>
            <endpointBehaviors>
              <behavior name="webHttpBehavior">
                <webHttp />
              </behavior>
            </endpointBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="ServiceConfig" name="MyServices">
                <endpoint address="srv" binding="webHttpBinding" contract="Operations" bindingConfiguration="webHttpBindingWithJsonP" behaviorConfiguration="webHttpBehavior" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8766" />
                    </baseAddresses>
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceConfig">
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    </system.serviceModel>
    

    Here’s a very good blog post that steps you through this.

    Hopefully this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.