.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

How to make my WCF client send JSON?

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :WCF
 
Hi, I have a WCF Service that accepts and sends JSON objects, defined like the following: [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/booking/", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] Int32 booking(order o); now I have used SvcUtil.exe to create a client class and using that, I am trying to access my service - but even though I use "webHttpBinding" with "webHttp" behavior, it always sends it's messages in xml. What do I have to do make my client speak JSON?  


View Complete Post


More Related Resource Links

make json call to send an email

  

the aspx:

<div class="contactSubmit">
                <asp:ImageButton ID="ibSubmit" runat="server" ValidationGroup="vgContact" /></div>


 

the jquery :

$(document).ready(function () {
            // Add the page method call as an onclick handler for the div.
            $(".contactSubmit").click(function () {
                $.ajax({
                    type: "POST",
                    url: "Home.aspx/GetDate",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        // Replace the div's content with the page method's return.
                        $(".contactSubmit").text(msg.d);
                    }
                });
            });
        });


The problem is that I need to use the text in a text box in my webmethod, and I can't because it's static, this results in a compilation error:

[WebMethod]
    public static string SendContactForm()
    {
        Mail.SendMailMessage(NameTextBox.Text);
    }

<

WCF - First call to Callback instance from Server takes considerable time to make it to the client.

  
Hello. There's a performance problem we are facing that we are unable to fix using DuplexChannels. The first call made by the client to the server reaches the server instantly. The first call made by the server to the first client using a Callback proxy will take several seconds to reach the client. All subsequent calls to the client (as well as other clients) will reach and execute instantly. The client connects to the Server using a proxy to IServiceProvision, supplies an instance to an implementation of IClientCallback and calls IServiceProvision.Start(). The server instantly processes the call and makes an asynchronous call to IClientCallback.DoWork(), which takes several seconds to enter the client's DoWork() implementation. The remainder of the execution then runs smoothly. Also, the server will experience such a slowdown only for the very first call of the first client that connects to it. Is it normal for the Callback interface to take so much time to warmup, only on the first call to the first client? Below is the full source code. Thanks for any information you may provide. Cheers Mike Shared Class Library using System.ServiceModel; namespace Test { [ServiceContract(Namespace = "http://test/IService", CallbackContract = typeof(IClientCallback))] public interface IServiceProvision { [OperationContract] void Start(); [OperationContract] void

Using AJAX Extenders To Make Client-Side Happy

  
I am developing a web application that needs to retrieve, display and write data to an SQL database.  I'm trying to use AJAX and Javascripts in order to populate fields, lists and data, and to have button and calendar controls on the page that can update the page without refreshing and losing the data page.  Therefore, it's necessary that I find ways to doing as much as possible (ideally, everything) client-side, without page refreshes. Now, for security purposes, I've heard that there's a method for retrieving a copy of all relevant data from SQL at loading time, keeping a copy of it, perhaps on a separate page, and send-retrieve-display this data on my page, and then, at Submission time, write this data back to the Server.  This is to minimize hits to the Server and to preserve data integrity.  I've heard that doing this is called using an Extender, but we can't find examples of how this works so far. Can anybody provide me with a code example of how this is done and what it looks like?  Trying to find out how this is done, and decide if it's practical. Any suggestions and questions are welcome.

Make my WCF service return json

  
Iam trying to make my wcf serivce method to return JASON-object, but it dosen't work, when I open in a webbrowser it shows xml. How can I make this method to return json.I have inserted [WebGet(ResponseFormat = WebMessageFormat.Json)],,,, but it didn't help[WebGet(ResponseFormat = WebMessageFormat.Json)] protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems() { // TODO: Change the sample implementation here if (items.Count == 0) { items.Add("A", new SampleItem() { Value = "A" }); items.Add("B", new SampleItem() { Value = "B" }); items.Add("C", new SampleItem() { Value = "C" }); } return this.items; }[WebGet(ResponseFormat = WebMessageFormat.Json)]         protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems()         {             // TODO: Change the sample implementation here             if (items.Count == 0)             {                 items.Add("A", new SampleItem() { Value = "A" });  &nb

consuming wcf Data service in different format in client - SOAP (including a WDSL), XML, JSON, etc.

  
Hi I have implemented wcf data service with entity framework with the following steps, i want to know i can we consume this WCF Data service in different format like (SOAP, JSON, XML, PLIST). it will be helpfull if some one help on this. - Created web application with VS2010 and added edmx file and selected tables,views and SPs that i want to use - imported SP with complex type by using function import. - Created WcfDataservice (.svc File). - in SVC File i have added [webget] method as follows.         [WebGet]        public List<GetSearchResultWithComplextype_Result> GetSearchResultComplextype(string email, string Title, string Color)        {            Entities db = new Entities();            var query = db.GetSearchResultWithComplextype(email, Title, Color);            List<GetSearchResultWithComplextype_Result> caseList = query.ToList<GetSearchResultWithComplextype_Result>();            return caseList;        } - created one more client application and added service reference. here i want to cons

consuming wcf Data service in different format in client - SOAP (including a WDSL), XML, JSON, etc.

  
Hi  I have implemented wcf data service with entity framework with the following steps, i want to know i can we consume this WCF Data service in different format like (SOAP, JSON, XML, PLIST). it will be helpfull if some one help on this. - Created web application with VS2010 and added edmx file and selected tables,views and SPs that i want to use - imported SP with complex type by using function import. - Created WcfDataservice (.svc File). - in SVC File i have added [webget] method as follows.         [WebGet]         public List<GetSearchResultWithComplextype_Result> GetSearchResultComplextype(string email, string Title, string Color)         {             Entities db = new Entities();             var query = db.GetSearchResultWithComplextype(email, Title, Color);             List<GetSearchResultWithComplextype_Result> caseList = query.ToList<GetSearchResultWithComplextype_Result>();             return caseList;         } - created one more client application and added service reference. here i wan

Create Email Message and Send to Client For Review before Sending

  

Please read this post carefully. I am not looking to actually send an email using ASP.NET. 

I am looking for a means by which ASP.NET can create an Outlook MailItem and stream it to the client machine for the user to review prior to sending. I know that its possible to create files such as Word docs and Excel spreadsheets an then stream them, but I don't know how to do it with ASP.NET.


which approach is better? client side callbacks or ajax using json for programming?

  

Hello! Friends,

                   I just wanted to know whether clientside callbacks or ajax is better for programming? I want to develop a webbased ERP. 


Thanks...


TCP Client/Server communication: NetworkStream.Write() send partial data unless close() method is re

  
Hi to all,
I wrote a simple client-server application that comunicate through NetworkStream class. The problems comes when stream.close() and client.close() methods are called. It look like only the first 10415 bytes are sent once those methods are called. So, if the data to send is more than this size, it is automatically truncated.

If I  remove both stream/client close() methods from the code, the data is fully received whatever the size is. I tried various alternative solutions (the ones marked as comments in the sample code), but none of them works.
The only thing that seems to work is adding a manual delay before the close() methods execute with something like that:

For Counter as integer = 0 to 10
     System.Threading.Thread.Sleep(1000)
     Application.DoEvents()
Next

The problem is that after delay I still don't know if all the data has been transfered or not. In addition to that, I will have to wait 10 seconds before sending another request, even if the response is just a few bytes of data. I could change at runtime the number of seconds to wait according to the size of the data to send, but I still think that delay is not a solution and will cause adverse effects.

So, for now the only working solution is to remove both Stream/Client Close() methods from

XmlDictionaryReaderQuotas content length quota (8192) error during client send to wcf

  

I have a silverlight app (non asp, non IIS) and wcf service.

When i read large data from the wcf service 60k+ then the silverlight app successfully retrieves the information from the wcf service.
However....
When i try to send (silverlight client to wcf service) large data 30k+ I get the XmlDictionaryReaderQuotas error but when I send 2k information then everything works fine.

This is my ServiceReferences.ClientConfig file

 

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647

Unable to send email with smtp client

  

I'm not able to get email working on my site. I have followed the instructions for this host. This should be very straightforward. Here is my current web.config.  

<system.net>
		<mailSettings>
			<smtp deliveryMethod="Network" from=".com">
				<network host="localhost" port="25" userName=".com" password="" />
			</smtp>
		</mailSettings>
	</system.net>
 
 Public Shared Function SendSimpleMail(ByVal fromAccount As String, ByVal toAccount As String, ByVal title As String, ByVal msg As String) As Boolean
            HttpContext.Current.Response.Write("FROM: " & fromAccount & " TO: " & toAccount & "TITLE: " & title & msg)
            Dim eMail As New System.Net.Mail.MailMessage()
            eMail.IsBodyHtml = True
            eMail.Body = msg
            eMail.From = New System.Net.Mail.MailAddress(fromAccount)
            eMail.[To].Add(toAccount)
            eMail.Subject = title
            Dim SMTP As New System.Net.Mail.SmtpClient
            'SMTP.UseDefaultCredentials = False
            'SMTP.Credentials = New System.Net.NetworkCredential(".com&quo

Should Lotus Notes Client be running or Open in background to send emails programatically using .NET

  

Hi

Does Lotus notes client be running or opened in the background to send emails using Lotus Notes with .Net?

    I am working on a task where my app should send emails using Lotus Notes with .NET . I am able to send mails also. But the problem comes when i close my Lotus Notes mail and try to run my application which sends mails. But the mails are not being delivered. Reason, they were being stored in "Outgoing mail". Again when i open my Lotus Notes client by entering my username and password, then the mails that were in "Outgoing mail" were been delivered. Should lotus notes client run on the background for my application to send emails? Is there any way that my application sends emails even if lotus notes is not opened? I'm struck with this issue all day, did lot of research, but i could find anything.

i used this link  as a base ref to send emails using .net http://www.ibm.com/developerworks/lotus/library/domino-msnet/  

Any help regarding this is greatly appreciated.


Send JSON Object to WCF

  

I have a WCF returning JSON correctly, however this WCF now needs to be extended to allow JSON Serialized objects to be posted to it. I am using JQuery to serialize objects and post it to the WCF, and when I run the project in Debug the method SimpleSearch() is being called and an object is being instantiated, however the properties are all null. Is there an error taking place in the deserialization from JSON?

Below is an extract of my WCF file, below this is the JavaScript calling the WCF using JQuery

[ServiceContract(Namespace = "http://www.link.co.uk/")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ATMService {        
       

        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json)]
        public void SimpleSearch(SimpleObj searchRequest) {
            // Once in here the searchRequest object both Name and Postcode are null      

            }
    }

    [DataContract]
    public class SimpleObj {
        public string Name { get; set; }
        public string PostCode{ get; set; }
    }

//jQuery
function search() {   

    var searchRequest = new Object();
    searchRequest.Name = "Chris";

    var dataToSend = '{"searchRequest":[' + JSON.stringify(searchRequest) + ']}';

    $.ajax({
        type: "PO

Use jQuery and ASP.NET AJAX to build a client side Repeater

  
By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

Client Side Gridview Pagination using JQuery

  
I would like to show how to use Client Side Gridview Pagination using Jquery Table Pagination Plugin by using Ryan Zielke.

Use jQuery and ASP.NET AJAX to build a client side Repeater

  
By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

To that end, I'm going to walk you through these four steps to effectively implementing a client side Repeater, using ASP.NET AJAX and jQuery:

Practical Multithreading for Client Apps

  
Writing applications that use multiple threads is often considered an advanced programming task, prone to errors. In this month's column, I'll focus on a practical application of multithreading in Windows® Forms applications with some real benefits, while attempting to keep things simple. My goal is to present multithreading in an approachable way that addresses a very common need: writing applications with a user interface that remain responsive to the user.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend