简体   繁体   English

在VB.NET中引用代码

[英]Referencing code in VB.NET

I'm not at all familiar with VB.NET or ASP. 我对VB.NET或ASP一点都不熟悉。 I need to create a simple page which makes a call to a remote web service. 我需要创建一个简单的页面来调用远程Web服务。 I used the wsdl utility which comes with the DotNet SDK to generate a service proxy and write it to a VB file. 我使用了DotNet SDK随附的wsdl实用程序来生成服务代理并将其写入VB文件。 Unfortunately I have no idea how to reference this code in either my ASPX file or the code behind VB file so I can create an instance of the proxy. 不幸的是,我不知道如何在我的ASPX文件或VB文件后面的代码中引用此代码,因此我可以创建代理的实例。

Edit: I should have qualified this by noting that I'm not using visual studio. 编辑:我应该通过指出我没有使用Visual Studio来对此进行限定。 I just coded up a .aspx with a .vb behind it and dropped it into an IIS location. 我只是在后面加上.vb的.aspx编码,然后将其放入IIS位置。 Is there a way to do what you're suggesting outside of VS? 有没有一种方法可以在VS之外完成您的建议?

You need to add this code into your project so that it can be consumed. 您需要将此代码添加到项目中,以便可以使用它。

Right click on your App_Code folder and select "Add Existing Item". 右键单击您的App_Code文件夹,然后选择“添加现有项”。 This will bring up explorer. 这将调出资源管理器。 Use it to select the generated file and it will add it to your project. 使用它选择生成的文件,它将添加到您的项目中。

Now you will be able to reference this code from within your page or code behind file 现在,您将可以从页面内或文件后面的代码中引用此代码

If there isn't an App_Code folder in your project, then right click on the project in solution explorer and select "Add New ASP.Net Folder"->App_Code 如果您的项目中没有App_Code文件夹,则在解决方案资源管理器中右键单击该项目,然后选择“添加新的ASP.Net文件夹”-> App_Code

Or, instead of the wsdl utility: 或者,代替wsdl实用程序:

In the solution explorer windows, r-click on the project, and select "add web reference". 在解决方案资源管理器窗口中,右键单击该项目,然后选择“添加Web参考”。 In the dialog that comes up, put in the url to the web service. 在出现的对话框中,输入Web服务的URL。 In the web reference name box (lower right of that dialog), put in whatever you want to local alias for the service to be called. 在“ Web参考名称”框中(该对话框的右下角),在您要调用的服务的本地别名中输入所需的内容。

So, if you put in a url of: 因此,如果您输入以下网址:

http://otherserver.com/otherservice.asmx http://otherserver.com/otherservice.asmx

And, a web reference name of: xyz 并且,网络参考名称为:xyz

To use it, your code would look like: 要使用它,您的代码应如下所示:

dim x as new xyz
var = x.methodname()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM