如何使用 ASMX Web 服务的不同代理类版本(生产或测试)

发布于 2024-08-12 14:37:04 字数 1795 浏览 2 评论 0原文

我在 Visual Studio 2005 中有一个 ASMX Web 服务作为一个单独的项目。为了追求“程序集分离”,每个 a CODE 杂志教程,我的代理类位于一个单独的类库项目中,不包含我的代码 - 只是一个名为 ASMXproxy 以及关联的 reference.csapp.config、.disco 和 .wsdl 文件。因此,编译后我有一个FileServiceProxy.dll

为了使用这个 WS,我在同一解决方案中有一个名为 FileServiceDemo 的 Web 应用程序项目。它没有 Web 引用,而是对 FileServiceProxy.dll 的“常规”引用。在我的 default.aspx.cs 文件中,我通过这些代码片段访问我的 WS:

using FileServiceProxy.ASMXproxy;
public partial class _Default : System.Web.UI.Page
{
    ASMXproxy.FileService brokerService;
protected void Page_Load(object sender, EventArgs e)
{
    try
        {
            brokerService = new ASMXproxy.FileService();

因此,虽然这种方式工作正常,但当我想要测试已部署的版本或对“localhost”版本进行更改时,我发现很尴尬。我不能简单地更改 app.config:

<applicationSettings>
    <FileServiceProxy.Properties.Settings>
        <setting name="FileServiceProxy_ASMXproxy_FileService" serializeAs="String">
            <value>http://localhost/TRIMBrokerService/FileService.asmx</value>
        </setting>
    </FileServiceProxy.Properties.Settings>
</applicationSettings>

简而言之,当我需要将我的 Web 应用程序发布到另一台服务器时,我必须更改代理类中的 Web 引用并重建它。然后,当我想在本地主机上调试它时,我必须将 Web 引用更改回本地主机(如上所述)。

理想情况下,我想在我的 Web 应用程序演示项目中公开某种选择(例如,单选按钮或用于在运行时更改 URL 的文本框),以便我可以为所需的 FileServiceProxy.dll 提供某种“后期绑定”在运行时使用。其他人已经草拟了提案“使用配置文件” 但我不知道如何做到这一点。在我看来,我必须有一个额外的项目,因此需要另一个 DLL - 也许是 FileServiceProxyPROD.dll - 但这看起来很尴尬,即使这样我也不确定我还需要做什么。

I've got an ASMX webservice as a separate project in Visual Studio 2005. In pursuit of "assembly separation" per a CODE Magazine tutorial, my proxy class is in a separate class library project containing no code of mine - just a web reference named ASMXproxy with the associated reference.cs, app.config, .disco and .wsdl files. Thus, when compiled I have a FileServiceProxy.dll.

For consuming this WS, I have a web app project called FileServiceDemo in this same solution. It has no web reference but instead a "regular" reference to FileServiceProxy.dll. In my default.aspx.cs file, I gain access to my WS via these snippets:

using FileServiceProxy.ASMXproxy;
public partial class _Default : System.Web.UI.Page
{
    ASMXproxy.FileService brokerService;
protected void Page_Load(object sender, EventArgs e)
{
    try
        {
            brokerService = new ASMXproxy.FileService();

So while things work OK this way, I find it awkward when I want to test a deployed version or make changes to a "localhost" version. I can't simply make changes to the app.config:

<applicationSettings>
    <FileServiceProxy.Properties.Settings>
        <setting name="FileServiceProxy_ASMXproxy_FileService" serializeAs="String">
            <value>http://localhost/TRIMBrokerService/FileService.asmx</value>
        </setting>
    </FileServiceProxy.Properties.Settings>
</applicationSettings>

In short, when I need to publish my web app to another server, I have to change the web reference in proxy class and rebuild it. Then when I want to debug it on my localhost, I have to change the web reference back to localhost (as above).

Ideally, I would like to expose some sort of choice (e.g. radio buttons or a textbox for altering a URL at runtime) in my web app demo project such that I could have a "late binding" of sorts for the desired FileServiceProxy.dll to be used at runtime. Others have sketched proposals "using config files" but I am stuck on how to do that. It appears to me that I would have to have an additional project and hence another DLL - perhaps FileServiceProxyPROD.dll - but this seems awkward and even then I'm not sure what else I'd have to do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-08-19 14:37:04

实际上,您可以使用相同的参考。只需更改代理实例的 Url 属性:

using (var svc = new WebServiceProxy())
{
    svc.Url = realUrl;
    var result = svc.ServiceMethod();
}

Actually, you can use the same reference. Just change the Url property of the proxy instance:

using (var svc = new WebServiceProxy())
{
    svc.Url = realUrl;
    var result = svc.ServiceMethod();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文