I have developed a WCF Webservice, to be called by jQuery. The WCF Webservice and the AJAX Client which enables the WCF Webservice are running on different Webservers.
Here are the Definition of the Webservice.
[ServiceContract]
interface IPersonService
{
[OperationContract]
Person InsertPerson(Person person);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class PersonService : IPersonService
{
...
[WebInvoke(UriTemplate = "/POST/PersonPost", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
public Person InsertPerson(Person person)
{
Debug.WriteLine("POST:[PersonId = {0} PersonName = {1}]", person.Id, person.Name);
return new Person(person.Id, person.Name);
}
}
[DataContract]
public class Person
{
[DataMember]
private string id;
[DataMember]
private string name;
public Person(string id, string name)
{
this.id = id;
this.name = name;
}
public string Id { get; set; }
public string Name { get; set; }
public override string ToString()
{
var json = JsonConvert.SerializeObject(this);
return json.ToString();
}
}
Here is the client:
$.ajax({
type: "POST",
data: { "id": "Mehrere ;;; trennen", "name": "GetPerson" },
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processData: false,
crossDomain: true,
url: "http://localhost:59291/Person/POST/PersonPost",
success: function (data) {
alert("Post erfolgreich: ");
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Fehler Post: Status " + xhr.status + " AntwortText " + xhr.responseText);
}
});
I get HTTP Code 200. That is not bad? But can somebody tell me, how I can have access to the data which the jQuery Client send to the WCF Service???
Thanks