GetReportWebServiceWithAuthentication() 方法用于配置远程报表代理,以及处理 NT 身份验证。
在本节中,将学习如何编写 GetReportWebServiceWithAuthentication() 方法的代码来设置 URL 和 Credentials 属性的值。必须将 GetReportWebServiceWithAuthentication() 方法添加到 CrystalReportViewer 控件的 ReportSource,以声明和实例化 RemoteReportProxy 类。
还可以使用此方法向 RemoteReportProxy 实例中添加防火墙代理设置。
- 在类的底部,创建返回 RemoteReportProxy 类的 GetReportWebServiceWithAuthentication() 私有帮助器方法。
``` vb
Private Function GetReportWebServiceWithAuthentication() As
RemoteReportProxy
End Function
```
``` csharp
private RemoteReportProxy GetReportWebServiceWithAuthentication()
{
}
```
- 在 ConfigureCrystalReports() 方法内,选择当前已赋给 CrystalReportViewer 控件的 ReportSource 属性的 Web 服务 URL 字符串。将该字符串剪切到剪贴板。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/8yfdxzdx.alert_note(zh-cn,VS.90).gif" alt="Note" class="note" />注意</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>在此过程后面的部分中,将对 CrystalReportViewer 控件的 ReportSource 属性赋以一个新值。</p></td>
</tr>
</tbody>
</table>
声明一个 reportWebServiceURL 字符串变量,并粘贴此前剪切的 URL 字符串。
Dim reportWebServiceURL As String = "http://mywebserviceserver.com/MyWebServiceDirectory/Hierarchical%20GroupingService.asmx"string reportWebServiceURL = "http://mywebserviceserver.com/MyWebServiceDirectory/Hierarchical%20GroupingService.asmx";声明并实例化 RemoteReportProxy 类。
Dim myRemoteReportProxy As RemoteReportProxy = New RemoteReportProxy()RemoteReportProxy remoteReportProxy = new RemoteReportProxy();将 reportWebServiceURL 变量赋给 RemoteReportProxy 实例的 URL 属性。
myRemoteReportProxy.Url = reportWebServiceURLremoteReportProxy.Url = reportWebServiceURL;调用 ConfigureAuthentication() 方法(将在下一个步骤中创建),然后将一个 TrueBoolean值和 reportWebServiceURL 变量传递到该方法中。将此方法赋给 RemoteReportProxy 实例的 Credentials 属性。
``` vb
myRemoteReportProxy.Credentials = ConfigureAuthentication(True,
reportWebServiceURL)
```
``` csharp
remoteReportProxy.Credentials = ConfigureAuthentication(true,
reportWebServiceURL);
```
- 调用 AddFirewallProxySettings() 方法(将在下一个步骤中创建),然后将一个 False 布尔值、防火墙代理服务器的 URI 字符串,以及 RemoteReportProxy 实例传递到该方法中。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/8yfdxzdx.alert_note(zh-cn,VS.90).gif" alt="Note" class="note" />注意</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>用您的防火墙代理服务器替换该 URI 字符串。</p></td>
</tr>
</tbody>
</table>
``` vb
myRemoteReportProxy = AddFirewallProxySettings(False, "<<
http://firewallproxyserver:8080>>",
myRemoteReportProxy)
```
``` csharp
remoteReportProxy = AddFirewallProxySettings(false, "<<
http://firewallproxyserver:8080>>",
remoteReportProxy);
```
从该方法中返回 RemoteReportProxy 实例。
Return myRemoteReportProxyreturn remoteReportProxy;