如何从Visual Studio 2008中的配置文件中提取ASP.NET Web引用的URL?

时间:2021-09-22 15:17:07

I have a web reference for our report server embedded in our application. The server that the reports live on could change though, and I'd like to be able to change it "on the fly" if necessary.

我有一个嵌入在我们的应用程序中的报表服务器的Web引用。报告所依赖的服务器可能会发生变化,我希望能够在必要时“即时”更改它。

I know I've done this before, but can't seem to remember how. Thanks for your help.

我知道我以前做过这个,但似乎无法记住。谢谢你的帮助。

I've manually driven around this for the time being. It's not a big deal to set the URL in the code, but I'd like to figure out what the "proper" way of doing this in VS 2008 is. Could anyone provide any further insights? Thanks!

我暂时手动驱动它。在代码中设置URL并不是什么大不了的事,但我想弄清楚在VS 2008中这样做的“正确”方式是什么。任何人都可以提供进一步的见解吗?谢谢!


In VS2008 when I change the URL Behavior property to Dynamic I get the following code auto-generated in the Reference class.

在VS2008中,当我将URL Behavior属性更改为Dynamic时,我在Reference类中自动生成以下代码。

Can I override this setting (MySettings) in the web.config? I guess I don't know how the settings stuff works.

我可以在web.config中覆盖此设置(MySettings)吗?我想我不知道设置的东西是如何工作的。

Public Sub New()
    MyBase.New
    Me.Url = Global.My.MySettings.Default.Namespace_Reference_ServiceName
    If (Me.IsLocalFileSystemWebService(Me.Url) = true) Then
        Me.UseDefaultCredentials = true
        Me.useDefaultCredentialsSetExplicitly = false
    Else
        Me.useDefaultCredentialsSetExplicitly = true
    End If
End Sub

EDIT

So this stuff has changed a bit since VS03 (which was probably the last VS version I used to do this).

所以这个东西自VS03以来有所改变(这可能是我以前做过的最后一个VS版本)。

According to: http://msdn.microsoft.com/en-us/library/a65txexh.aspx it looks like I have a settings object on which I can set the property programatically, but that I would need to provide the logic to retrieve that URL from the web.config.

根据:http://msdn.microsoft.com/en-us/library/a65txexh.a​​spx看起来我有一个设置对象,我可以在其上以编程方式设置属性,但我需要提供检索的逻辑来自web.config的URL。

Is this the new standard way of doing this in VS2008, or am I missing something?

这是在VS2008中这样做的新标准方式,还是我错过了什么?

EDIT #2

Anyone have any ideas here? I drove around it in my application and just put the URL in my web.config myself and read it out. But I'm not happy with that because it still feels like I'm missing something.

这里有人有什么想法吗?我在我的应用程序中开车绕过它,然后自己将URL放在我的web.config中并将其读出来。但我对此并不满意,因为它仍然感觉我错过了一些东西。

2 个解决方案

#1


3  

In the properties window change the "behavior" to Dynamic.

在属性窗口中,将“行为”更改为动态。

See: http://www.codeproject.com/KB/XML/wsdldynamicurl.aspx

#2


0  

If you mean a VS2005 "Web Reference", then the generated proxy classes have a URL property that is the SOAP endpoint url of that service. You can change this property and have your subsequent http communications be made to that new endpoint.

如果您指的是VS2005“Web引用”,则生成的代理类具有URL属性,该属性是该服务的SOAP端点URL。您可以更改此属性,并将后续的http通信发送到该新端点。

Edit: Ah, thanks bcaff86. I didn't know you could do that simply by changing a property.

编辑:啊,谢谢bcaff86。我不知道你可以通过改变一个属性来做到这一点。

#1


3  

In the properties window change the "behavior" to Dynamic.

在属性窗口中,将“行为”更改为动态。

See: http://www.codeproject.com/KB/XML/wsdldynamicurl.aspx

#2


0  

If you mean a VS2005 "Web Reference", then the generated proxy classes have a URL property that is the SOAP endpoint url of that service. You can change this property and have your subsequent http communications be made to that new endpoint.

如果您指的是VS2005“Web引用”,则生成的代理类具有URL属性,该属性是该服务的SOAP端点URL。您可以更改此属性,并将后续的http通信发送到该新端点。

Edit: Ah, thanks bcaff86. I didn't know you could do that simply by changing a property.

编辑:啊,谢谢bcaff86。我不知道你可以通过改变一个属性来做到这一点。