如何使用vb.net代码在另一个aspx应用程序中使用ASMX Web服务? [英] How to consume ASMX Web Service in another aspx application using vb.net code?

查看:65
本文介绍了如何使用vb.net代码在另一个aspx应用程序中使用ASMX Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我已经创建了一个asmx Web服务,该服务将与SQL Server数据库进行交互以获取,插入和更新数据库中的某些表.
我有一个称为AddItem的Service方法,该方法将类对象作为参数.使用该参数,我将值插入数据库.以同样的方式,我有另一个服务方法,该方法使用相同的类从db获取所有项目,并返回该类对象作为服务的返回类型.

这是我的示例AddItem()和GetAllItems()原型

Hi friends,
I have created a asmx web service.The service will interact with SQL Server database to Get, Insert and Update of some tables in my db.
I have one Service method called AddItem which takes a class object as parameter. with that parameter I am inserting the values into the database. In the same way I have another service method that Gets all the Items from db using the same class and returns the class object as the return type for my service.

Here is my sample AddItem() and GetAllItems() prototype

<WebMethod()> _
   Public Function GetAllItems(ByVal AgencyId As Integer) As List(Of Item)
       Return InventoryManager.GetAllItems()
   End Function


和我的

AddItem()
 Public Function AddItem(ByVal ThisItem As Item) As Integer
            Return InventoryManager.AddItem(ThisItem) 
    End Function


我创建了一个必须使用该服务的aspx应用程序.我创建了Web表单以在我的aspx应用程序中显示项目.
一切正常,就像我也可以运行服务和Web应用程序一样.

我正在使用Jquery ajax函数的服务.

要使用我的服务,我必须在IIS中托管,因为我已按照此站点中的menthiond步骤进行操作
在此处检查 [ ^ ]

当我运行Web应用程序时,无法从服务中获取数据.我可能遗漏了什么?我是否走错路了?
这是从Web应用程序调用服务的Jquery代码.


and I created a aspx application that has to consume that service. I have created web forms to display the items in my aspx application.
Everything is works fine like I am able to run the service and web application also.

I am consuming the service from Jquery ajax function.

To consume my service I have to host in IIS for that I have followd the steps menthiond in this site
Check Here[^]

while I run my web app I am unable to get the data from my service What probable I am missing? Whether I am gone in wrong way?
here is my Jquery code of calling the service from my web application

try {
           var DTO = { "ThisItem": Item };
           var ItemDetails = JSON.stringify(DTO);
           alert(ItemDetails);
           $.ajax
                ({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "http://localhost/InventoryWebServicePub/InventoryService.asmx/AddItem",
                    data: ItemDetails,
                    dataType: "json",
                    success: function () { alert("Success"); },
                    error: function () { alert("Error Occured"); }
                });
       }
       catch (err) {
           alert("Error in Get Items " + err.Message);
       }


请任何人都可以告诉我,看来我已经粘贴了很长的一件事,这是我需要确切说明我所做的一切的全部内容.

谢谢
Ganesh


Please any one could tell me, it seems that I have pasted a long matter its all that I need to tell exactly what I did?

Thanks
Ganesh

推荐答案

.ajax ({ 类型:" , contentType:" , 网址:" , 数据:ItemDetails, dataType:" , 成功:功能(){alert(" ); }, 错误:功能(){警报(" ); } }); } 捕获(错误){ alert(" + err.Message); }
.ajax ({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://localhost/InventoryWebServicePub/InventoryService.asmx/AddItem", data: ItemDetails, dataType: "json", success: function () { alert("Success"); }, error: function () { alert("Error Occured"); } }); } catch (err) { alert("Error in Get Items " + err.Message); }


请任何人都可以告诉我,看来我已经粘贴了很长的一件事,这是我需要确切说明我所做的一切的全部内容.

谢谢
Ganesh


Please any one could tell me, it seems that I have pasted a long matter its all that I need to tell exactly what I did?

Thanks
Ganesh


这篇关于如何使用vb.net代码在另一个aspx应用程序中使用ASMX Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆