Strange when I startup the service directly it shows me:
UserService Service
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
svcutil.exe http://localhost:90/WebServices/UserService.svc?wsdl
This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:
C#
class Test
{
static void Main()
{
UserServiceClient client = new UserServiceClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}
Visual Basic
Class Test
Shared Sub Main()
Dim client As UserServiceClient = New UserServiceClient()
' Use the 'client' variable to call operations on the service.
' Always close the client.
client.Close()
End Sub
End Class
n8900498
Member
47 Points
69 Posts
Cannot process the message because the content type "application/json; charset=utf-8" was not the...
Jan 18, 2013 03:36 PM|LINK
Hi
I am get the above response when calling a WCF service via ajax json. My calling code is:
<script type="text/javascript"> $(document).ready(function () { $.ajax ({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://localhost:90/WebServices/UserService.svc/Calculate", data: "{}", timeout: 10000, dataType: "json", success: function (response) { alert(response) }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.statusText); alert(thrownError); } }); }); </script>My service is:
[ServiceContract] public interface IUserService { [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json )] Answer Calculate(); } [DataContract] public class Answer { [DataMember] public string answer { get; set; } }My method is :
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class UserService : IUserService { public Answer Calculate() { Answer answer = new Answer(); answer.answer="Hello World"; return answer; } }Any help will be appreciated !!!
kushalrdalal
Contributor
7128 Points
1270 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Jan 18, 2013 06:12 PM|LINK
Try -
My Blog
LinkedIn Profile
n8900498
Member
47 Points
69 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Jan 18, 2013 06:26 PM|LINK
I tried that but that still didn't work, it gave me :
kushalrdalal
Contributor
7128 Points
1270 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Jan 18, 2013 07:01 PM|LINK
So your error says that it was expected to get text/xml instead of json?
My Blog
LinkedIn Profile
n8900498
Member
47 Points
69 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Jan 18, 2013 07:16 PM|LINK
Seems like it
kushalrdalal
Contributor
7128 Points
1270 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Jan 18, 2013 09:00 PM|LINK
When you directly see your service in browser can you able to go to the help page and see the calculate method.
Can you click that method and does says the request format in json or not?
My Blog
LinkedIn Profile
n8900498
Member
47 Points
69 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Jan 18, 2013 09:15 PM|LINK
Strange when I startup the service directly it shows me:
UserService Service You have created a service. To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax: svcutil.exe http://localhost:90/WebServices/UserService.svc?wsdl This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example: C# class Test { static void Main() { UserServiceClient client = new UserServiceClient(); // Use the 'client' variable to call operations on the service. // Always close the client. client.Close(); } } Visual Basic Class Test Shared Sub Main() Dim client As UserServiceClient = New UserServiceClient() ' Use the 'client' variable to call operations on the service. ' Always close the client. client.Close() End Sub End ClassNico_He
Member
114 Points
27 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Jan 21, 2013 08:21 AM|LINK
What is the issue now?
n8900498
Member
47 Points
69 Posts
Re: Cannot process the message because the content type "application/json; charset=utf-8" was not...
Feb 06, 2013 04:40 PM|LINK
I have eventually solved the major problem, I needed to add
to my SVC markup. e.g.