Reporting Services - Using a web service via a cus

2019-07-28 01:12发布

问题:

I'm having a problem when using a Custom Assembly in my reports. We are using a Microsoft SQL Server 2012 Express Edition with Reporting Services and are designing our reports in Microsoft Visual Studio 2010

Scenario: In Reporting Services we want to base the language of a report based on a parameter. All the strings are translated with the help of a web service that has a simple "Translate" method. Because we cannot reference to a web service in the report, we used a custom assembly that accesses the web service. After giving the assembly the correct permissions, placing the .dll in the correct places everything worked as a charm.

Problem: When the web service is referenced to in the custom assembly a app.config file is generated with a system.serviceModel node as seen below.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="ITranslatorServicebinding" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="WebServiceAddress"
            binding="basicHttpBinding" bindingConfiguration="TranslatorServicebinding"
            contract="Translator.ITranslatorService" name="ITranslatorServicePort" />
    </client>
</system.serviceModel>

Appearantly when a dll is used in an application, that dll's config file should be at the location of the application that references it. Because I have no idea where to store this particular config file when using Reporting Services I decided to add it programmatically via the following code:

var remoteAddress = new System.ServiceModel.EndpointAddress(YourWebServiceURI);
using (var translateService = new Translator.TranslatorServiceClient(new System.ServiceModel.BasicHttpBinding(), remoteAddress))
{
   translateService.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 1, 0);
   return translatedString = translateService.Translate(ISOCode, NativeString);
}

This was enough for the assembly to find the web service and use it. However, as you can see, the YourWebServiceUri is hardcoded in the assembly. I want to avoid this. Then I decided to add a key in the web.config file of Reporting Services like this:

<appSettings>
  <add key="WebServiceUri" value="YourWebServiceURI"/>
</appSettings>

However, if, for some reason I want to change settings in the basicHttpBinding then I'd have add this programmatically and rebuild the assembly. To avoid this, I want to know if I could Copy&Paste the ServiceModel somewhere in a config file so that the Reporting Services can recognize it.

QUESTION: Which config file do I need to adjust in order for the custom assembly to pick up the endpoint and manage to connect to the web service?

You can already assume I have the correct permissions set up and that the dll is in the correct place. I do not know however where to store the app.config, or which configuration file I need to alter.

回答1:

In the end it was the web.config I need to alter with the system.serviceModel. It's important to restart the Report Server otherwise the changes will not take effect. Problem fixed.