1

Hi I have next WCF service.

[OperationContract]     
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
//[WebInvoke(UriTemplate = "GetStores?dataViewID={dataViewID}&filter={filter}&extent={extent}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,)]
string GetStores(int dataViewID, string filter, MapExtent extent);

[DataContract]
public class MapExtent
{
    [DataMember]
    public double XMax { get; set; }

    [DataMember]
    public double XMin { get; set; }

    [DataMember]
    public double YMax { get; set; }

    [DataMember]
    public double YMin { get; set; }
}

jQuery part is next

//var mapextend = { XMax: 1.0, XMin: 1.0, YMax: 10.5, YMin: 4.5 };
var paramData = {"dataViewID":12, "filter":"", extent : {"XMax": 1.0, "XMin": 1.0, "YMax": 10.5, "YMin": 4.5} };
$.ajax({
    url: serviceurl + 'GetStores',
    type: 'GET',
    contentType: 'application/json',
    data: paramData,
    success: function (result) {
        alert(result);                    
        },
    error: function (xhr) {
        alert(xhr);
        }
    });

Config look like it

<system.serviceModel>

    <bindings>
      <webHttpBinding>
         <binding name="webBinding"></binding>
      </webHttpBinding>           
    </bindings>

    <behaviors>

      <endpointBehaviors>
        <behavior name="jsonBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>

      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>

    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

    <services>           
      <service behaviorConfiguration="ServiceBehavior" name="MyService">
        <endpoint address="" binding="webHttpBinding"  bindingConfiguration="webBinding" contract="IMyService" behaviorConfiguration="jsonBehavior" />        
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

When ajax call this service it calls but all parameters doesn't get any values. What i doing wrong ?

1 Answer 1

2

Try this:

jQuery part:

//var mapextend = { XMax: 1.0, XMin: 1.0, YMax: 10.5, YMin: 4.5 };
        var paramData = {"dataViewID":12, "filter":"", extent : {"XMax": 1.0, "XMin": 1.0, "YMax": 10.5, "YMin": 4.5} };
        $.ajax({
            url: serviceurl + 'GetStores',
            type: 'POST',
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(paramData),
            success: function (result) {
                alert(result);                    
            },
            error: function (xhr) {
                alert(xhr);
            }
        });
Sign up to request clarification or add additional context in comments.

1 Comment

I fagot about dataType: "json"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.