Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

consume asp.net wcf by jquery ajax

Posted on 2015-01-13
3
575 Views
Last Modified: 2015-01-16
I have below codes create wcf and consume wcf by jquery ajax.
And you can take a look of attached document for error.
One screen showing I use wcf utility to check the service is actually working fine.
second image shown error message. and I don't know why it happens.

Can you help me? Take a look of the code consuming side and see anything wrong?

Thanks,

12<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
      <script type="text/javascript">
          // Urls to access the WCF Rest service methods
           $(document).ready(function () {
              $.ajax({
                  type: "GET",
                  dataType: "json",
                  contentType: "application/json; charset=utf-8",
                  processData: true,
                  url: "http://localhost:62937/ServiceJVC.svc?wsdl/NetPrice/",
                  data: JSON.stringify({ "companyNo":"062", "customerNo": "337557", "modelList":"KDAV300,KDX40,CSGW1200", "qtyList":"10,1,5", "orderDateTime":"11/07/2014", "repNo": "SA7" }),
                  success: function (data, status, jqXHR) {
                      //alert("success" + data);
                      alert("success");
                  },
                  error: function (xhr) {
                      alert(xhr.responseText);
                      alert("Error");
                  }
 
 
              });
          });
 
       
    </script>
 
 
 
    [ServiceContract]
    public interface IServiceJVC
    {
        [OperationContract]
        [WebInvoke(Method = "GET",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "NetPrice/{companyNo}/{customerNo}/{modelList}/{qtyList}/{orderdateTime}/{repNo}")]
        string NetPrice(string companyNo, string customerNo, string modelList, string qtyList, string orderDateTime, string repNo);
    }
0
Comment
Question by:ITsolutionWizard
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40548601
Hi,
from what I can see from your implementation, you have a RESTfull service. Therefore your service call from jQuery needs to set the parameters inside the url and not inside the message as JSON.

Alternative 1:
Adjust the jQuery AJAX url and pass the parameters inside the url

Alternative 2:
Change your webservice to a dedicated service which expects the parameter inside the call as JSON data

HTH
Rainer
0
 

Author Comment

by:ITsolutionWizard
ID: 40548909
I don't quite understood what you mean. Can you show me in codes? Thanks
0
 

Author Comment

by:ITsolutionWizard
ID: 40550235
any updates?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question