我在报告中使用自定义程序集时遇到问题.我们正在使用带有 Reporting Services 的 Microsoft SQL Server 2012 Express Edition,并且正在 Microsoft Visual Studio 2010 中设计我们的报表
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
场景:在 Reporting Services 中,我们希望基于参数来确定报表的语言.所有字符串都在具有简单翻译"方法的 Web 服务的帮助下进行翻译.因为我们无法在报告中引用 Web 服务,所以我们使用了访问 Web 服务的自定义程序集.在为程序集提供正确的权限后,将 .dll 放在正确的位置,一切都变得很有吸引力.
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.
问题:在自定义程序集中引用 Web 服务时,会生成带有 system.serviceModel 节点的 app.config 文件如下所示.
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>
显然,当在应用程序中使用 dll 时,该 dll 的配置文件应该位于引用它的应用程序的位置.因为在使用 Reporting Services 时我不知道在哪里存储这个特定的配置文件,所以我决定通过以下代码以编程方式添加它:
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);
}
这足以让程序集找到 Web 服务并使用它.但是,如您所见,YourWebServiceUri 在程序集中是硬编码的.我想避免这种情况.然后我决定在 Reporting Services 的 web.config 文件中添加一个密钥,如下所示:
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>
但是,如果出于某种原因我想更改 basicHttpBinding 中的设置,那么我会以编程方式添加它并重建程序集.为了避免这种情况,我想知道是否可以将 ServiceModel 复制并粘贴到配置文件中的某个位置,以便 Reporting Services 能够识别它.
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.
问题:我需要调整哪个配置文件才能让自定义程序集获取端点并设法连接到 Web 服务?
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?
您已经可以假设我设置了正确的权限并且 dll 位于正确的位置.但是,我不知道将 app.config 存储在哪里,或者我需要更改哪个配置文件.
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.
最后是 web.config 我需要用 system.serviceModel 进行更改.重新启动报表服务器很重要,否则更改将不会生效.问题已解决.
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.
这篇关于Reporting Services - 通过自定义程序集使用 Web 服务:查找端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!