How To Read The Base64 Encoded Xml Of A WCF Message



TODO:

Have you ever wanted to get the Base64 encoded Xml of your WCF message?

 

SOLUTION:

public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
      try
      {
           //create a copy for use
           MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
           Message newMessage = buffer.CreateMessage();
          
           //assign original so it can be used again
           request = buffer.CreateMessage();
           string messageBody = string.Empty;

           //read the message
           using (XmlDictionaryReader bodyReader = newMessage.GetReaderAtBodyContents() 
           {
                bodyReader.ReadStartElement("Binary");
                byte[] bodyBytes = bodyReader.ReadContentAsBase64();
                messageBody = Encoding.UTF8.GetString(bodyBytes);
           }

           //....do your other stuff here, the messageBody will now contain your text.
      }
      catch (Exception x)
      {
            return null;
      }
}

 

NOTES:

There are no notes on this topic.

WebInvoke Verbs To Use With Restful WCF Service



TODO:

Have you ever wanted to know which verbs to use when defining your OperationContract in a WCF service?

 

SOLUTION:

// Get an employee by ID - GET - employee/id (  [WebGet(UriTemplate = "/employee/{id}")] )

// Create a new employee - POST - employee  [WebInvoke(Method = "POST", UriTemplate = "/employee/{xml}")] )

// Update an employee - PUT - employee/id  [WebInvoke(Method = "PUT", UriTemplate = "/employee/{xml}")]

// Delete an employee - DELETE - employee/id  [WebInvoke(Method = "DELETE", UriTemplate = "/employee/{id}")]

 

NOTES:

There are no notes on this topic

How To Fix "Endpoint not found" Error When Browsing Restful WCF Service In Visual Studio



TODO:

You try to view your Restful WCF service in a browser from Visual Studio and get the "Endpoint not found" error.

 

SOLUTION:

Right click on your .svc file.  Look for "Factory="= "System.ServiceModel.Activation.WebServiceHostFactory" and delete it.  You can now Right click your .svc file and choose "View in browser"

 

NOTES:

There are no notes on this topic

How To Throttle How Many Message Are Pulled From MSMQ



TODO:

You have an MSMQ that is wired to a WCF service.  You want to throttle how many messages are processed, so that you can better control the system resources.  To do so, you need to change the config file for your WCF...and add the following entries.

 

SOLUTION:

<behaviors>
 <serviceBehaviors>
  <behavior name="DefaultThrottlingBehavior">
   <serviceThrottling maxConcurrentCalls="jQuery15207601982052437961_1377884886132?"
          maxConcurrentSessions="???"
          maxConcurrentInstances="???" />
  </behavior>
 </serviceBehaviors>
</behaviors>

 

NOTES:

Replace the ??? with the values you want.  It may take some trial and error to see what settings work best.

How To Throttle How Many Message Are Pulled From MSMQ



TODO:

You have an MSMQ that is wired to a WCF service.  You want to throttle how many messages are processed, so that you can better control the system resources.  To do so, you need to change the config file for your WCF...and add the following entries.

 

SOLUTION:

<behaviors>
 <serviceBehaviors>
  <behavior name="DefaultThrottlingBehavior">
   <serviceThrottling maxConcurrentCalls="xxx"
          maxConcurrentSessions="xxx"
          maxConcurrentInstances="xxx" />
  </behavior>
 </serviceBehaviors>
</behaviors>

 

NOTES:

Replace the xxx with the values you want.  It may take some trial and error to see what settings work best.

How To Throttle How Many Message Are Pulled From MSMQ



TODO:

You have an MSMQ that is wired to a WCF service.  You want to throttle how many messages are processed, so that you can better control the system resources.  To do so, you need to change the config file for your WCF...and add the following entries.

 

SOLUTION:

<behaviors>
 <serviceBehaviors>
  <behavior name="DefaultThrottlingBehavior">
   <serviceThrottling maxConcurrentCalls="jQuery15207601982052437961_1377884886134?"
          maxConcurrentSessions="???"
          maxConcurrentInstances="???" />
  </behavior>
 </serviceBehaviors>
</behaviors>

 

NOTES:

Replace the ??? with the values you want.  It may take some trial and error to see what settings work best.

How To Throttle How Many Message Are Pulled From MSMQ



TODO:

You have an MSMQ that is wired to a WCF service.  You want to throttle how many messages are processed, so that you can better control the system resources.  To do so, you need to change the config file for your WCF...and add the following entries.

 

SOLUTION:

<behaviors>
 <serviceBehaviors>
  <behavior name="DefaultThrottlingBehavior">
   <serviceThrottling maxConcurrentCalls="jQuery15207601982052437961_1377884886133?"
          maxConcurrentSessions="???"
          maxConcurrentInstances="???" />
  </behavior>
 </serviceBehaviors>
</behaviors>

 

NOTES:

Replace the ??? with the values you want.  It may take some trial and error to see what settings work best.

How To Throttle How Many Message Are Pulled From MSMQ



TODO:

You have an MSMQ that is wired to a WCF service.  You want to throttle how many messages are processed, so that you can better control the system resources.  To do so, you need to change the config file for your WCF...and add the following entries.

 

SOLUTION:

<behaviors>
 <serviceBehaviors>
  <behavior name="DefaultThrottlingBehavior">
   <serviceThrottling maxConcurrentCalls="xxx"
          maxConcurrentSessions="xxx"
          maxConcurrentInstances="xxx" />
  </behavior>
 </serviceBehaviors>
</behaviors>

 

NOTES:

Replace the 'xxx' with the values you want.  It may take some trial and error to see what settings work best.

How To Fix "The maximum string content length quota (8192) has been exceeded while reading XML data." error when calling WCF



TODO:

How to fix the error "The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader"

 

SOLUTION:

1.  Open your web.config. 

2.  Look for the binding entry for your Service. (<basicHttpBinding><binding name=...)

3.  Replace the value in the attribute maxStringContentLength="8192" with "2147483647"

 

NOTES:

There are no notes on this topic.