Reporting Services-通过自定义程序集使用Web服务:查找端点 [英] Reporting Services - Using a web service via a custom assembly: Finding the endpoint
问题描述
在报表中使用自定义程序集时遇到问题。我们正在将Microsoft SQL Server 2012 Express Edition与Reporting Services一起使用,并在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服务时,将生成一个 app.config 文件,其中一个 system.serviceModel 节点,如下所示。
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服务:查找端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!