Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: WebServices Pin
Mycroft Holmes8-May-18 20:31
professionalMycroft Holmes8-May-18 20:31 
Questionc# Why can I not get this to work? Pin
tomas0007-May-18 1:21
tomas0007-May-18 1:21 
AnswerRe: c# Why can I not get this to work? Pin
Luc Pattyn7-May-18 2:42
sitebuilderLuc Pattyn7-May-18 2:42 
AnswerRe: c# Why can I not get this to work? Pin
User 74293389-May-18 23:24
professionalUser 74293389-May-18 23:24 
Questionnow how can i get the splitted values in a textbox from seperate line in c# using text file Pin
Mohamed Fahad M6-May-18 4:14
Mohamed Fahad M6-May-18 4:14 
AnswerRe: now how can i get the splitted values in a textbox from seperate line in c# using text file Pin
Gerry Schmitz6-May-18 5:02
mveGerry Schmitz6-May-18 5:02 
AnswerRe: now how can i get the splitted values in a textbox from seperate line in c# using text file Pin
OriginalGriff6-May-18 6:47
mveOriginalGriff6-May-18 6:47 
QuestionThe data contract type “…” cannot be deserialized because the required data members Pin
Ruhul Md Amin5-May-18 9:36
Ruhul Md Amin5-May-18 9:36 
In my Application, I have a WCF service. I am trying to send a Json Object and get the Json object as Response.

But every time, I am getting error "The data contract type 'TestConsole.localhostrREF4.PrimeDataProperty' cannot be deserialized because the required data members 'isPrimeResultField, isPrimeResultFieldSpecified, isPrimeResultSpecified1Field, isPrimeResultSpecified1FieldSpecified, numberField, numberFieldSpecified, numberSpecifiedInField, numberSpecifiedInFieldSpecified' were not found.

My Web Service name is "ISAJsonWebService"

Here is my code of Web Service:

IJsonWebService.cs

[ServiceContract] public interface IJsonWebService {

[OperationContract]
[WebInvoke(UriTemplate = "/GetData",
Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
PrimeDataPropertyOut GetData(PrimeDataProperty value);

}

[DataContract]
public class PrimeDataProperty
{
[DataMember]
public int number { get; set; }
[DataMember]
public bool NumberSpecifiedIn { get; set; }
[DataMember]
public bool IsPrimeResult { get; set; }
[DataMember]
public bool IsPrimeResultSpecified { get; set; }
}

[DataContract]
public class PrimeDataPropertyOut
{
[DataMember]
public bool IsPrimeResultOut { get; set; }
[DataMember]
public bool IsPrimeResultSpecifiedOut { get; set; }
}
EndPoint Code behind JsonWebService.svc.cs

public class JsonWebService : IJsonWebService
{
public PrimeDataPropertyOut GetData(PrimeDataProperty value)
{
return new PrimeDataPropertyOut
{
IsPrimeResultOut = true,
IsPrimeResultSpecifiedOut = true
};
}

}
Here is my Web Config:


<configuration>
<appsettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true">

<system.web>
<compilation debug="true" targetframework="4.7.1">
<httpruntime targetframework="4.7.1">


<system.servicemodel>
<diagnostics>
<messagelogging logmalformedmessages="true"
="" logmessagesattransportlevel="true">

<services>
<service behaviorconfiguration="serviceBehavior"
="" name="ISAJsonWebService.JsonWebService">
<endpoint address="" behaviorconfiguration="jsonEndpointBehavior"
="" binding="webHttpBinding" name="json" contract="ISAJsonWebService.IJsonWebService">
<identity>
<dns value="localhost">


<endpoint address="mex" binding="mexHttpBinding" name="mex"
="" contract="IMetadataExchange">
<endpoint address="wsHttpBinding" behaviorconfiguration="wsHttpBinding"
="" binding="wsHttpBinding" bindingconfiguration="" name="wsHttpBinding" contract="ISAJsonWebService.IJsonWebService">
<identity>
<dns value="localhost/wsHttpBinding">




<behaviors>
<endpointbehaviors>
<behavior name="jsonEndpointBehavior">
<webhttp>

<behavior name="wsHttpBinding">

<servicebehaviors>
<behavior name="serviceBehavior">
<servicemetadata httpgetenabled="true">
<servicedebug includeexceptiondetailinfaults="true">




<system.webserver>
<modules runallmanagedmodulesforallrequests="true">
<directorybrowse enabled="true">



I am trying to Consume the web service from a Console App.

Here is the code:

static void Main(string[] args)
{
localhostrREF4.JsonWebService jsonWebServiceRef = new
localhostrREF4.JsonWebService();

PrimeDataProperty pdp = new PrimeDataProperty { number = 1,
NumberSpecifiedIn = false, IsPrimeResult = false, IsPrimeResultSpecified
= false };

WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
MemoryStream ms = new MemoryStream();

DataContractJsonSerializer serializer = new
DataContractJsonSerializer(typeof(PrimeDataProperty));
serializer.WriteObject(ms, pdp);

byte[] data =
client.UploadData("http://localhost:65256/JsonWebService.svc/GetData",
"POST", ms.ToArray());
Stream stream = new MemoryStream(data);


var obj = new DataContractJsonSerializer(typeof(PrimeDataProperty));
**var returnPrimeDataProperty = obj.ReadObject(stream) as
PrimeDataProperty;**
}
in the last line (Bold Text) is throwing exception.

Please let me know, what I am missing.

Thanks.
AnswerRe: The data contract type “…” cannot be deserialized because the required data members Pin
OriginalGriff5-May-18 20:45
mveOriginalGriff5-May-18 20:45 
GeneralRe: The data contract type “…” cannot be deserialized because the required data members Pin
Ruhul Md Amin6-May-18 1:52
Ruhul Md Amin6-May-18 1:52 
Questionwhen have you used a C# SortedList<TKey, TValue> ? Pin
BillWoodruff5-May-18 7:44
professionalBillWoodruff5-May-18 7:44 
AnswerRe: when have you used a C# SortedList<TKey, TValue> ? Pin
Gerry Schmitz5-May-18 8:42
mveGerry Schmitz5-May-18 8:42 
GeneralRe: when have you used a C# SortedList<TKey, TValue> ? Pin
BillWoodruff5-May-18 23:21
professionalBillWoodruff5-May-18 23:21 
GeneralRe: when have you used a C# SortedList<TKey, TValue> ? Pin
Gerry Schmitz6-May-18 4:33
mveGerry Schmitz6-May-18 4:33 
GeneralRe: when have you used a C# SortedList<TKey, TValue> ? Pin
BillWoodruff6-May-18 6:55
professionalBillWoodruff6-May-18 6:55 
GeneralRe: when have you used a C# SortedList<TKey, TValue> ? Pin
Gerry Schmitz6-May-18 7:33
mveGerry Schmitz6-May-18 7:33 
GeneralRe: when have you used a C# SortedList<TKey, TValue> ? Pin
BillWoodruff6-May-18 23:23
professionalBillWoodruff6-May-18 23:23 
AnswerRe: when have you used a C# SortedList<TKey, TValue> ? Pin
jschell5-May-18 11:29
jschell5-May-18 11:29 
GeneralRe: when have you used a C# SortedList<TKey, TValue> ? Pin
BillWoodruff5-May-18 23:25
professionalBillWoodruff5-May-18 23:25 
GeneralRe: when have you used a C# SortedList<TKey, TValue> ? Pin
jschell12-May-18 9:22
jschell12-May-18 9:22 
GeneralInvalid column name 'NoteTotal' , how to fix it to this error in Sql server Pin
Member 105327485-May-18 7:33
Member 105327485-May-18 7:33 
GeneralRe: Invalid column name 'NoteTotal' , how to fix it to this error in Sql server Pin
Eddy Vluggen5-May-18 7:43
professionalEddy Vluggen5-May-18 7:43 
GeneralRe: Invalid column name 'NoteTotal' , how to fix it to this error in Sql server Pin
Gerry Schmitz5-May-18 7:44
mveGerry Schmitz5-May-18 7:44 
QuestionI need to get the next next text from text file Pin
Mohamed Fahad M5-May-18 3:04
Mohamed Fahad M5-May-18 3:04 
AnswerRe: I need to get the next next text from text file Pin
Richard MacCutchan5-May-18 3:21
mveRichard MacCutchan5-May-18 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.