Solved

consume asp.net wcf by jquery ajax

Posted on 2015-01-13
3
374 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery, html5 UI 1 49
jquery, dropdown 4 37
Asp.net mvc entity issue 6 20
Handle null when using linq in this line 1 20
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now