在Asp中调用asp.net web服务(asmx)(经典或简单) [英] call asp.net web service (asmx ) in Asp (classic or simple )

查看:89
本文介绍了在Asp中调用asp.net web服务(asmx)(经典或简单)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有asp(经典)应用



我需要做的是..



i必须开发Web服务(asmx)以使用Asp.net(4.0或3.5)执行某些功能





我可以称之为此网络在Asp(经典)应用程序中服务?



如果是,那么如何?



感谢您的宝贵回复。 。



谢谢

i have asp ( classic ) application

what i need to do is..

i have to develop web service ( asmx ) to perform some functionality using Asp.net (4.0 or 3.5 )


can i call this web service in Asp( classic ) application ?

if yes then how ?

Appreciate your valuable response..

thanks

推荐答案

是的,你可以这样做。 CodeProject有一篇文章解释了如何做到这一点 - 从ASP3调用WebService .0和JavaScript [ ^ ]。



如需更多阅读材料 - Google搜索 - 来自经典asp的asp.net网络服务 [ ^ ]



希望有所帮助!
Yes you can do that. CodeProject has an article which explains how to do it - Calling a WebService from ASP3.0 and JavaScript[^].

For more readings - Google Search - asp.net web service from classic asp[^]

Hope that helps!


你也可以直接在VB脚本中完成。

使用下面,

第1步 - 创建一个简单的ASP.Net ASMX服务



You can do it directly in VB script also.
Use Below,
Step 1 - Created a simple ASP.Net ASMX service

namespace TestService
{
using System;
using System.Web.Services;

    /// <summary>
    /// Summary description for MyService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class MyService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }        

        [WebMethod]
        public string[] PostData(Param param)
        {
            return new string[] { "value1", "value2", param.ParamId, param.ParamName };
        }
  }
   [Serializable]
    public class Param
    {
        public string ParamId { get; set; }
        public string ParamName { get; set; }
    }
}










<!--#include file="common.asp"-->
<body>
    <%  
     
        Dim str :  str = GetWSData("http://localhost/TestService/MyService.asmx", "HelloWorld", "")        
        
        Dim PostData : PostData = "<param><ParamId>value3</ParamId><ParamName>Value4</ParamName></param>"             
        Dim str1 : str1 = GetWSData("http://localhost/TestService/MyService.asmx", "PostData", PostData)                    
    %>
    <div>Hellow friends Time is now <%	=Time%>	</div>
    <div>My Name is <%=name %>11</div>
    <div>
        <![CDATA[ Some data here ]]>
        GET Response is  <%= str %>
        <br />
        POST Response is <%= str1 %>
    </div>
    
</body>










'''******* In Common.asp *****

Dim svcURI : svcURI = "http://tempuri.org/"

Function GetRequestBody(strMethodName, strPostData)
    Dim postContainer : postContainer = "<" & strMethodName & " xmlns=""" & svcURI & """>"
    postContainer = postContainer & strPostData & "</" & strMethodName & ">"
    GetRequestBody = postContainer
End Function 

function GetSoapEnvelope(xmlStr)    
    Dim soapEnvelope 
    soapEnvelope = "<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
    soapEnvelope = soapEnvelope & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""> "
    soapEnvelope = soapEnvelope & "<soap:Body>"
    soapEnvelope = soapEnvelope & xmlStr & "</soap:Body></soap:Envelope>"
    GetSoapEnvelope = soapEnvelope
 end function	


 Function GetWSData(svcUrl, strMethodName, paramData)
    Dim resBody,reqBody     
    reqBody = GetRequestBody(strMethodName, paramData)  
    reqBody = GetSoapEnvelope(reqBody)
    resBody = CallWSMethod("POST",svcUrl,strMethodName, reqBody)    
    GetWSData = resBody'GetResultData(resBody, strMethodName)
 End function 

function CallWSMethod(strMethod, svcUrl, methodName, requestBody)
    Dim strUsername : strUsername = ""
    Dim strPasssword : strPasssword = ""
    Dim IsAsync : IsAsync = false
    Dim serviceResponse : serviceResponse = ""
    Dim objHttp
       
    'Set and Instantiate our working objects
    Set objHttp = Server.CreateObject("MSXML2.XMLHTTP")
    With objHttp 
        '.open strMethod, svcUrl, IsAsync, strUsername, strPasssword
        .open strMethod, svcUrl, IsAsync
        .setRequestHeader "Content-Type", "text/xml; charset=utf-8"    
        .setRequestHeader "SOAPAction", svcURI & methodName
        .send(requestBody)              
    End With     
    serviceResponse = objHttp.ResponseText
    
    set objHttp = Nothing
    CallWSMethod = serviceResponse
 End function


这篇关于在Asp中调用asp.net web服务(asmx)(经典或简单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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