1

Is it possible to have a WCF service also perform as a web service client?

If this IS possible, can you offer me some guidance on how to configure the client settings in the config file?

The main issue I'm having is that I'm sending large messages to my main REST service. When that message is relayed to the secondary service it seems that the response triggers a "MaxReceivedMessage" too large error. I've tried to configure the CLIENT setting for my REST service and have not been successful.

Which config do I define it in...the app.config or the web.config?

It seems that I am doing it wrong as no matter where I declare the CLIENT settings the binding is ignored.

Here is my APPLICATION config for the REST service.

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IBBIImageWarpService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8080/BBIImageWarp" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IBBIImageWarpService"
                contract="ServiceReference1.IBBIImageWarpService" name="BasicHttpBinding_IBBIImageWarpService" />
        </client>
    </system.serviceModel>
</configuration>

HERE IS THE ENDPOINT METHOD ON MY REST SERVICE that is failing:

        public ServiceResponse<DataContracts.BBIImgObject> WarpImage(DataContracts.BBIImgObject imgObject)
        {
            try
            {

                writeMessage("converting to JSON");

                string JSON = new JavaScriptSerializer().Serialize(imgObject);

                BasicHttpBinding binding = new BasicHttpBinding();

//SHOULD I ADD THE MAXRECEIVEDMessageSize TO THIS BINDING???

                EndpointAddress address = new EndpointAddress("http://localhost:8080/BBIImageWarp");

                ServiceReference1.BBIImageWarpServiceClient ImgWarpSvc = new ServiceReference1.BBIImageWarpServiceClient(binding, address);

                string rslt = ImgWarpSvc.WarpImageJSON(JSON);

                DataContracts.BBIImgObject cloneImgObject = new DataContracts.BBIImgObject();
                cloneImgObject.Base64EncodedImageData = rslt;
                cloneImgObject.BodyTypeID = imgObject.BodyTypeID;

                return new ServiceResponse<DataContracts.BBIImgObject>(String.Empty, ServiceResponse<DataContracts.BBIImgObject>.ResponseTypeEnum.BbiSuccess, cloneImgObject);
            }
            catch (Exception ex)
            {
                writeMessage(ex.Message);
                return new ServiceResponse<DataContracts.BBIImgObject>(ex.Message, ServiceResponse<DataContracts.BBIImgObject>.ResponseTypeEnum.BbiFailure, null);
            }
        }
tronious
  • 1,547
  • 2
  • 28
  • 45

1 Answers1

1

You can easily make a client using the same binaries

  1. Include the DLL of your service class to your client project.
  2. Create a channel factory from your service interface.
  3. Consume the channel factory.

For more information according to your requirements, please see http://msdn.microsoft.com/en-us/library/ms576132(v=vs.110).aspx

For the max received error, you need to do the following: The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property

Or from the code:

WebHttpBinding binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;

Similarly on the client side also.

Community
  • 1
  • 1
DJ'
  • 1,760
  • 1
  • 13
  • 26
  • Thanks for your reply. For #1 -> My REST service is acting like a client in the sense that it is also calling a separate service. That separate service is application hosted...it's created at runtime. There's no DLL for that service. For #2 -> How do I get a reference to that service interface? The only reference I've added is a reference to the service itself. – tronious Sep 15 '14 at 15:13
  • Thanks Dee Jay. The MaxReceivedMessageSize is my problem. I added additional code to the post. Would you mind reviewing it? It should give additional context to my issue. I've added the call that's failing – tronious Sep 15 '14 at 15:20
  • Dee Jay...this didn't 100% solve my problem but your answer absolutely pointed me in the right direction. Thanks for your help. – tronious Sep 15 '14 at 15:26
  • @tronious I am glad it helped. I am on my way home from work, I will check how i can help you further. Please tell me the current situation you are stuck in? – DJ' Sep 15 '14 at 15:28
  • Dee Jay, I am actually no longer stuck. Like I said your answer helped me get where I needed. The solution was certainly related to the MaxReceivedMessageSize property. I just was not setting it in the proper location. Your answer both helped me to find the proper location and better understand the existing code I wrote (strange as that may sound :) ). Thanks again for taking the time to help me. Cheers – tronious Sep 15 '14 at 15:30