Hi,
FYI: My WCF are quite limited and did not do anything like the following:
I need to create a wcf service that clients can communicate with sending / receiving JSON objects.
The eventual client is going to be mobile apps (developed by another company) so while developing I figured I'll "consume" the service using jQuery in a MVC app.
Figured I'll simplify my problem where FireBug keep telling me I have an "Invalid Label" in my result ( {"Id":199,"Name":"Krokonoster"} )
Here's some code for what it might help to tell me what I'm doing wrong:
Code:
$('#getPerson').click(function (event) {
event.preventDefault();
$.ajax({
dataType: 'jsonp',
contentType: "application/json",
type: "GET",
url: "http://localhost:8732/service1/data/" + $("#personId").val(),
success: function (data) {
alert(data.Name);
}
});
});
Code:
[ServiceContract]
public interface IService1
{
[OperationContract]
Person GetData(string id);
}
Code:
public class Service1 : IService1
{
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "data/{id}")]
public Person GetData(string id)
{
return new Person()
{
Id = Convert.ToInt32(id),
Name = "Krokonoster"
};
}
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
Code:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="app.service.Service1">
<endpoint address="http://localhost:8732/service1"
binding="webHttpBinding"
contract="app.service.IService1"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
I guess this is just the beginning of my troubles since I still have to get to posting full JSON objects to my service, etc.
Guess going over a good book will help?
Got these (any recommendations? time's a limited)
- Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
- Pro WCF 4
- WCF 4 Step by Step