Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF Call Passing a Null Parameter
    primarykey
    data
    text
    <p>I have a WebHttpBinding WCF service that I am calling. My first POST method send the object correctly, but subsequent calls to POST methods are passing null for the object. </p> <p>Here is my service:</p> <pre><code>public void Update(ObjectDTO objectDTO) { string token = WebOperationContext.Current != null ? WebOperationContext.Current.IncomingRequest.Headers["token"] : string.Empty; //Authentication bool isUserAuthenticatedResult = IsUserAuthenticated(ref token); if (!isUserAuthenticatedResult) return null; //Perform service action MyDtoManager = new MyDtoManager(); objectDTO = MyDtoManager.Update(objectDTO); return objectDTO; } </code></pre> <p>Here is my Service Contract:</p> <pre><code>[ServiceContract] public interface IMyDtoService { [OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] List&lt;ObjectDTO&gt; LoadById(string value); [OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] List&lt;ObjectDTO&gt; Load(string field, string value); [OperationContract] [WebInvoke(Method="GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] List&lt;ObjectDTO&gt; LoadAll(); [OperationContract(Name = "InsertSingle")] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] ObjectDTO Insert(ObjectDTO objectDto); [OperationContract(Name = "UpdateSingle")] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] ObjectDTO Update(ObjectDTO objectDto); [OperationContract(Name = "DeleteSingle")] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] ObjectDTO Delete(ObjectDTO objectDto); } </code></pre> <p>Here is my server configuration:</p> <pre><code>&lt;system.serviceModel&gt; &lt;bindings&gt; &lt;webHttpBinding&gt; &lt;binding name="WebHttpBindingConfig" openTimeout="00:05:00" sendTimeout="00:05:00" maxBufferSize="65536000" maxBufferPoolSize="52428800" maxReceivedMessageSize="65536000" transferMode="Buffered"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="65536000" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;security&gt; &lt;transport /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/webHttpBinding&gt; &lt;/bindings&gt; &lt;services&gt; &lt;service behaviorConfiguration="Services.ServiceBehavior" name="Services.MyDtoService"&gt; &lt;endpoint address="" behaviorConfiguration="HttpBehavior" binding="webHttpBinding" name="Services.MyDtoService" contract="ServiceInterfaces.IMyDtoService"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="Services.ServiceBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true" /&gt; &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="HttpBehavior"&gt; &lt;webHttp /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;/system.serviceModel&gt; </code></pre> <p>And finally my client code making the call:</p> <pre><code>IMyDtoService myDtoService = new WebChannelFactory&lt;IMyDtoService&gt;(BindingConfig, new Uri("http://localhost:8080/MyDtoService.svc")).CreateChannel(); using (new OperationContextScope((IClientChannel)myDtoService)) { if (WebOperationContext.Current != null) WebOperationContext.Current.OutgoingRequest.Headers.Add("token", tokenResult.Result); ObjectDTO insertResult = ipAddressService.Insert(new ObjectDTO { ObjectGuid = Guid.NewGuid(), IsAllow = true, Identifier = 1, IdentifierType = 0, StartIpAddress = "192.168.0.1" }); List&lt;ObjectDTO&gt; loadByIdResult1 = myDtoService.LoadById(insertResult.ObjectGuid.ToString()); Console.WriteLine("Insert Found: " + loadByIdResult1.Count); insertResult.IsAllow = false; ObjectDTO updateResult = ipAddressService.Update(insertResult); } </code></pre> <p>As you can see my client code calls my WCF service and the insert method works perfectly fine and I can see the persisted object in my database. However on the update, the ObjectDTO parameter is null. If I load an existing object and perform an update it works perfectly. It appears to be an issue with subsequent calls to the WCF service using POST methods. I do not have this problem with GET methods.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload