Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight 4.0: Using WebClient UploadStringAsync POST request to .Net 4 Webservice
    primarykey
    data
    text
    <p>I'm trying to get this code to run:</p> <p>Silverlight App xaml.cs:</p> <pre><code>private void SavePoiRequest(MyPushpin pin) { WebClient wc = new WebClient(); wc.Headers["Content-Type"] = "application/x-www-form-urlencoded"; wc.Encoding = Encoding.UTF8; wc.UploadStringCompleted += new UploadStringCompletedEventHandler((sender, e) =&gt; { if (e.Error != null) { return; } AddressTextBox.Text = e.Result; }); String name = pin.Name; String lat = pin.Location.Latitude.ToString().Replace(",","."); String lng = pin.Location.Longitude.ToString().Replace(",","."); String address = pin.Address; String photodesc = pin.PhotoDesc; String poistory = pin.Tag.ToString(); StringBuilder sr = new StringBuilder(); sr.Append("createpoi?name="+name+ "&amp;lat=" + lat + "&amp;lng=" + lng + "&amp;adr=" + address + "&amp;desc=" + photodesc + "&amp;story=" + poistory); String parameter = sr.ToString(); wc.UploadStringAsync(new Uri("http://localhost:80/"), "POST", parameter); AddressTextBox.Text = parameter; } </code></pre> <p>Webservice cs:</p> <pre><code>[WebInvoke(UriTemplate = "createpoi?name={name}&amp;lat={latitude}&amp;lng={longitude}&amp;adr={address}&amp;desc={photodescription}&amp;story={poistory}", Method = "POST")] public String SetPoiPOST(string name, string latitude, string longitude, string address, string photodescription, string poistory) { int newid = -1; POI_Man poimanager = new POI_Man(); MemoryStream resultstream = new MemoryStream(); if (!string.IsNullOrEmpty(name) &amp;&amp; !string.IsNullOrEmpty(latitude) &amp;&amp; !string.IsNullOrEmpty(longitude) &amp;&amp; !string.IsNullOrEmpty(address) &amp;&amp; !string.IsNullOrEmpty(photodescription) &amp;&amp; !string.IsNullOrEmpty(poistory) ) { //newid = poimanager.CreatePOI_alt(address, name, photodescription, poistory); newid = poimanager.CreatePOI(name, latitude, longitude, address, photodescription, poistory); poimanager.Generate("xml"); resultstream = poimanager.WriteMessage(newid.ToString()); WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"; } if (poimanager.NoError) { resultstream = poimanager.WriteMessage(newid.ToString()); WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"; //resultstream = (this.GetPoi(newid.ToString()) as MemoryStream); } else { resultstream = poimanager.WriteMessage("Beim anlegen des POI ist ein Fehler aufgetreten." + Environment.NewLine + "Haben Sie einen Parameter vergessen?"); WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain"; } return newid.ToString(); } </code></pre> <p>The web service doesn't get nothing from the client. Am I doing something wrong?</p> <p>I can contact the Server via a POST-request through WebClient OpenWriteAsync. But I need the response of the server for the lastID, so I use UploadStringAsync instead. Could you please help me?</p> <p>Bye Chau</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload