Yashwant Shukla
Вы также можете сделать это непосредственно в VB-скрипте.
использовать ниже,
Шаг 1-создан простой ASP.Нетто-службы asmx
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