开发者

Unable to reference webservice (.asmx) in my ASP.NET Project

开发者 https://www.devze.com 2023-02-05 06:21 出处:网络
In my current project, I have a webservice file called MyServices.asmx. This webservice I want to reference in my Default.aspx.cs file.

Unable to reference webservice (.asmx) in my ASP.NET Project

In my current project, I have a webservice file called MyServices.asmx. This webservice I want to reference in my Default.aspx.cs file.

My Code:

    MyServices newService = new MyServices();

    newService.addUser(txFirstName.Text, txLastName.Text, txtEmail.Text, 
txtUserName.Text, txtPassword.Text, txtBalance.Text);

But when I refer to that webservice (as shown below), I get error saying: "The type or namespace name 'MyServices' could not be found (are you missing a using directive or an assembly reference?)"

What should I do to correct this error?

Current So开发者_Go百科lution of Adding Service Reference still gives me that error. Can you please suggest what could be wrong?


You need to add a service reference to it.

In the project holding the Default.aspx.cs file, right click on "Service References" -> Add service reference.

You can then just click the "Discover" button to have the webservice listed.
Select it and click "OK".


Assuming that you added the reference and called the reference MyServices when you added it...

MyServices is the name you gave the reference when you added it. You need to find the name of the actual service.

For example, we have a web services website, and it contains many different web services (asmx files). Assume we have one called EmployeeInformationService

In Visual Studio, I might add a reference to it and choose the name "MyServices" as you did. To reference it in code I would need to put:

MyServices.EmployeeInformationService  newService = new MyServices.EmployeeInformationService(); 


I was able to resolve my problem by creating another webservice file.

Instead of MyService.asmx, I created a new one called MyServ.asmx and copied the code from MyService.asmx

By doing that, I was able to get the webservice reference in my code.

0

精彩评论

暂无评论...
验证码 换一张
取 消