Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

09 October, 2013

No set method for property in WCF service

Problem:

I have some class that I'm passing as a result of a service method, and that class has a get-only property:
 

public string PropertyName
{
    get
    {
        return "Some Value";
    }    
}

 I'm getting an exception on service side "No set method for property"

Solution:

Remember that WCF needs to create an instance of the object from its serialized representation (often XML) and if the property has no setter it cannot assign a value. Objects are not transferred between the client and the server but only serialized representations, so the object needs to be reconstructed at each end.

Make setter property private. So, client can never see the set method on your property acting much like a read only property. 

public string PropertyName
{
    get
    {
        return "Some Value";
    }
    private set
    { }
}

02 August, 2013

WCF: The maximum array length quota (16384) has been exceeded while reading XML data

Error:
"The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader."

Solution:

Try to change config file:

Add <readerQuotas> and set maxArrayLength="2147483647"

<binding name="WSHttpBinding_IBackup"
         closeTimeout="1:00:00"
         maxBufferPoolSize="2147483647"
         maxBufferSize="2147483647"
         maxReceivedMessageSize="2147483647"
         openTimeout="1:00:00"
         receiveTimeout="1:00:00"
         sendTimeout="1:00:00"
         transferMode="Streamed">
 
  <readerQuotas
    maxArrayLength="2147483647"
    maxBytesPerRead="2147483647"
    maxDepth="2147483647"
    maxNameTableCharCount="2147483647"
    maxStringContentLength="2147483647" />
 
  <!--if any issue then try this one-->
  <!--<textMessageEncoding messageVersion="Soap11" 
                       maxReadPoolSize="2147483647" 
                       maxWritePoolSize="2147483647">
    <readerQuotas
      maxArrayLength="2147483647"
      maxBytesPerRead="2147483647"
      maxDepth="2147483647"
      maxNameTableCharCount="2147483647"
      maxStringContentLength="2147483647" />
  </textMessageEncoding>-->
 
</binding>
 
If you have same issue then try following solution.
Reason:-
  • My service is simply ignoring my binding “basicHttp_ServiceName” and it’s always taking default binding
  • Reason is
    • My configuration service name does not match with service name in Service Host
    • The name I given is "ServiceName" where it has to be "XYZ.ServiceName"
    • E.g.
      <%@ ServiceHost Language="C#" 
                      Debug="true" 
                      Service="XYZ.ServiceName" 
                      CodeBehind="ServiceName.svc.cs" %>
      
      
Fix :-
  • Right click your “.svc” file and choose “View Markup”
  • Copy the Service name and paste it in your service name
  • Now my Service configuration looks below
  • E.g
     <services>
        <service name="XYZ.ServiceName">
     
        </service>
      </services>