如何拨打电话消耗Web服务(用ASP.NET 2.0和VB.NET编写) [英] How to call & consume a webservice (write in ASP.NET 2.0 and VB.NET)

查看:54
本文介绍了如何拨打电话消耗Web服务(用ASP.NET 2.0和VB.NET编写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!是否可以使用来自同一个aspx页的asp.net 2.0 e vb.net(Visual Studio 2005)中的Web服务写入内容?

我有一个"helloworld"网络服务,可以正常工作.

代码非常简单(该文件称为Service.vb):

 导入 System.Web
导入 System.Web.Services
导入 System.Web.Services.Protocols

< WebService(Namespace:= " )> _
< WebServiceBinding(ConformsTo:= WsiProfiles.BasicProfile1_1)> _
< Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
公共 服务
     继承 System.Web.Services.WebService

    < WebMethod()> _
    公共 功能 HelloWorld() As  字符串
        返回 " 
    结束 功能

结束  




现在,我单击按钮(Deafult.aspx代码)从aspx页启动Webservice.

 <  表单   目标  ="    动作  ="  方法   POST" <   > 
      <   tr  > 
        <   td     ="   150" 对齐  左" > 您好:<  /td  > 
        <   td  >  <  /td  > 
        <   td     ="  右" <    类型  ="      ="   class    >  <  /td  > 
      <  /tr  > 
    <  /table  > 
<  /form  >  





Service.asmx调用Service.vb中的类

 <%@     WebService    语言  ="  vb"  CodeBehind   〜/App_Code/Service.vb"   ="  %>  






结果是

 <? xml version = "  encoding = "  <  字符串    ="   http://tempuri.org/" >  Hello World <  /string  >  





我在新窗口中看到了这一点.


简而言之,一切都很简单,但是现在我需要在同一个aspx页面中查看结果,但是不幸的是,我很难过...

有人有什么建议吗?
PS:对不起,我的英文:)

解决方案

通过浏览解决方案中的Web服务"将您的服务页面添加到Web参考文件夹中.
(如果不存在Web参考文件夹,则在解决方案资源管理器中,右键单击项目/解决方案名称,选择添加Web参考".)

这将显示解决方案中所有服务页面的列表.

选择上面的服务页面.

它将显示服务描述.

提供网络参考名称,然后单击添加参考.

在您的.aspx页面中引用它.

创建您的Web服务对象后,调用方法HelloWorld().


很抱歉,我是Web服务的初学者...
我已经做完了所有事情,现在从Visual Studio中遇到这种情况:




但是如何在.aspx页面中使用Web参考呢?

谢谢:)


从default.aspx替换下面的行

旧的

 <  表单   目标  ="    动作  ="  Service.asmx/HelloWorld" 方法   POST"  <  表单   目标  ="    动作  ="  Service.asmx/HelloWorld" 方法  ="  >                           pre> 


Hi all! Is possible to consuming a webservice write in asp.net 2.0 e vb.net (visual studio 2005) from the same aspx page?

I have a "helloworld" webservice that works without problems.

The code is very simple (the file is called Service.vb):

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
     Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

End Class




At the moment i launch the webservice from the aspx page at the click on a button (Deafult.aspx code)

<form target="_blank" action="Service.asmx/HelloWorld" method="POST">
    <table>
      <tr>
        <td width="150" align="left">Hello:</td>  
        <td></td>
        <td align="right"> <input type="submit" value="Submit" class="button"></td>
      </tr>
    </table>
</form>





The Service.asmx calls the class in Service.vb

<%@ WebService Language="vb" CodeBehind="~/App_Code/Service.vb" class="Service" %>






The result is

<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">Hello World</string>





and I see this in a new windows.


In short, everything is very simple, but now I have the need to see the result in the same aspx page, but unfortunately I''m having a hard time...

Does anyone have any advice?
PS: and sorry for my english :)

解决方案

Add your service page to Web reference folder by browsing to ''web service in your solution''.
(If web reference folder is not present then, In solution explorer right click on project/solutuion name, select Add web reference.)

This will show list of all service pages in your solution.

Select the above service page.

It will display service description.

Give web reference name and click on Add reference.

Refer it in your .aspx page.

After creating object of your web service call method HelloWorld().


Sorry but I''m a beginner with the web service...
I have done everything and now, from Visual Studio, I have this situation:




But how can I use the web reference in the .aspx page?

Thanks :)


Replace below line from default.aspx

old

<form target="_blank" action="Service.asmx/HelloWorld" method="POST">

new

<form target="_self" action="Service.asmx/HelloWorld" method="POST">


这篇关于如何拨打电话消耗Web服务(用ASP.NET 2.0和VB.NET编写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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