Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

consume asp.net wcf by jquery ajax

Posted on 2015-01-13
3
Medium Priority
?
920 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
[X]
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
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 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
 
LVL 1

Author Comment

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

Author Comment

by:ITsolutionWizard
ID: 40550235
any updates?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…
Suggested Courses

730 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