2
votes

I have this WCF service:

    [ServiceContract]
        public interface IService
        {
            [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/PostComments", BodyStyle = WebMessageBodyStyle.Wrapped,
                       RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            string PostComments(string ItemId, string Comments, string FullName, string Location);
        }

    [DataContract]
        public class Comment
        {
            [DataMember]
            public string ItemId { get; set;}
            [DataMember]
            public string Comments { get; set;}
            [DataMember]
            public string FullName { get; set;}
            [DataMember]
            public string Location { get; set;}
        }

public class Service : IService
    {
       int i = 0;
       public string PostComments(string ItemId, string Comments, string FullName, string Location)
         {
            int Id;
            Id = Convert.ToInt32(ItemId);           
                adp = new SqlDataAdapter("insert into tblComment(intId,strComments,strFullName,strLocation,dtPosted,blnApprove) values("+Id+",'"+Comments+"','"+FullName+"','"+Location+"',GetDate(),1)", offcon);
                adp.Fill(ds1,"Comment");
                DataTable dt = ds1.Tables["Comment"];
                i++;
            }
            if (i > 0)
            {
                return "Comment Successfully Submitted.";
            }
            else
            {
                return "Comment falied to Submit.";
            }
        }

The Final URL is ::http://192.168.1.11/Service.Svc/PostComments

Now my main question is that how to do POST Action in WCF when client is JAVA ?

I get this Error:

The server encountered an error processing the request. The exception message is 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details. The exception stack trace is:

at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

This is the error when i am trying to run Post method in services.. I dont know how to fix.. But it is working perfectly fine in .net application. But not in JAVA. How to fix this.

1

1 Answers

1
votes

Sorry Guys this was damn Content-type error: i set Content-Type as application/json

and after this the error is about getting raw data from JAVA code i told them to send me JSON object means pure Json Data.

and after this the error left is only foreign key value is conflicting. and at last the error solved after doing all this.

But also don't forget to check your code of Java as it might possible that your code is the problem check content type n all of your code.