Try our conversational search powered by Generative AI!

System.InvalidOperationException on ImageServiceClient


I use EPiServer.ImageLibrary ImageServiceClient RenderImage method to render a cropped image. This was the code before upgrade to EPiServer CMS 11.5 and this was working fine.

var imageService = new ImageServiceClient("ImageServiceClientEndPoint");

After the upgrade, this code shows a compile error;

'ImageServiceClient.ImageServiceClient(string)' is obsolete: 'Use constructor that takes options instead, read options from container' 

Accordingly, I changed the code as follows;

ImageServiceOptions options = new ImageServiceOptions();
options.ClientEndpoint = "ImageServiceClientEndPoint";
var imageService = new ImageServiceClient(options);

Then I was able to compile successfully. But now this throws this exception;

System.InvalidOperationException: 'Could not find endpoint element with name 'ImageServiceClientEndPoint' and contract 'EPiServer.ImageLibrary.IImageService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.'

What have I done wrong here? 

Edited, Apr 17, 2018 11:40

Hi Helani,

Do you have something like the following in your web.config:

      <endpoint name="ImageServiceClientEndPoint"
                contract="EPiServer.ImageLibrary.IImageService" />
      <netTcpBinding >
         <binding name="ImageServiceBinding" maxReceivedMessageSize="20000000">
            <readerQuotas maxArrayLength="20000000" />
            <security mode="None">
      </netTcpBinding >
Apr 17, 2018 15:13

Hi Paul,

Thanks for the reply. I added this endpoint configuration to web.config and now the System.InvalidOperationException is fixed. 

However the imageService.RenderImage() method now returns a null. 

byte[] newImageBuffer = imageService.RenderImage(imageBuffer, operations, imageMimeType, zoomFactor, 100);

This method correctly worked when using the ImageServiceClient("ImageServiceClientEndPoint") constructor before EPiServer upgrade. Am I missing something?

Apr 18, 2018 6:17

Hi Helani,

Do you also have the image service itself configured in <system.serviceModel>?

    <service name="EPiServer.ImageLibrary.ImageService">
        <endpoint address="net.tcp://serverxyz:8000/ImageService"
                   contract="EPiServer.ImageLibrary.IImageService" /> 
Apr 18, 2018 10:46

No. Now I added ImageService configuration as well.

But the RenderImage() method still returns a null. 

Apr 18, 2018 11:21

Any error message in the logs?

Try iisreset.

Apr 19, 2018 23:46

The setting ClientEndpoint property on ImageServiceOptions is to be used if you want to host the ImageService in another application/process as your web application, in that case you need to specify an endpoint in web.config as stated before. You can also (which is the default behavior) run the image service in-process then you just leave the ClientEndpoint property empty/null on then imageServiceOptions class. 

Apr 20, 2018 9:12
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.