ASP示例:

<%
uid="账号"
pwd="密码"
tos="13900041123"
msg="你们好"
url = "http://URL/Service.asmx/SendMessages"
SoapRequest="uid="&uid&"&pwd="&pwd&"&tos="&tos&"&msg="&msg&"&otime="
''''''''''''''''''''''''''以下代码不变''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"'注意
xmlhttp.setRequestHeader "HOST","URL"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send(SoapRequest)
If xmlhttp.Status = 200 Then
 Set xmlDOC = server.CreateObject("MSXML.DOMDocument")
 xmlDOC.load(xmlhttp.responseXML) 
 showallnode "string",xmlDOC'调用SHOWALLNODE
 Set xmlDOC = nothing
Else
 Response.Write xmlhttp.Status&"&nbsp;"  
 Response.Write xmlhttp.StatusText
End if
Set xmlhttp = Nothing

Function showallnode(rootname,myxmlDOC)
 set nodeobj=myxmlDOC.documentElement.selectSingleNode("//"&rootname&"")'当前结点对像
 if nodeobj.text<>"" then
  returnstring=returnstring&"返回值:"&nodeobj.text
 end if
 response.write returnstring
 set nodeobj=nothing
End Function
%>

或者

function SendMessages(uid,pwd,tos,msg,otime)
SoapRequest="<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
"<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
"xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
"<soap:Body>"& _
"<SendMessages xmlns="&CHR(34)&"http://tempuri.org/"&CHR(34)&">"& _
"<uid>"&uid&"</uid>"& _
"<pwd>"&pwd&"</pwd>"& _
"<tos>"&tos&"</tos>"& _
"<msg>"&msg&"</msg>"& _
"<otime>"&otime&"</otime>"& _
"</SendMessages>"& _
"</soap:Body>"& _
"</soap:Envelope>"

Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
xmlhttp.setRequestHeader "HOST","URL"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.setRequestHeader "SOAPAction", "http://tempuri.org/SendMessages" '一定要与WEBSERVICE的命名空间相同,否则服务会拒绝
xmlhttp.Send(SoapRequest)
''样就利用XMLHTTP成功发送了与SOAP示例所符的SOAP请求.'检测一下是否返回200=成功:

If xmlhttp.Status = 200 Then
        Set xmlDOC = server.CreateObject("MSXML.DOMDocument")
        xmlDOC.load(xmlhttp.responseXML)
            SendMessages=xmlDOC.documentElement.selectNodes("//SendMessagesResult")(0).text '显示节点为GetUserInfoResult的数据(返回字符串)
        Set xmlDOC = nothing
    Else
        SendMessages=xmlhttp.Status&"&nbsp;"
        SendMessages=xmlhttp.StatusText
    End if
        Set xmlhttp = Nothing
end function

Delphi示例:

procedure TForm1.Button2Click(Sender: TObject);
 var
uid,pwd,mob,txt:WideString;
  Iservice:   Service1Soap;
  back_info:string;
begin
    HTTPRIO1.URL:=service_url.Text;
    HTTPRIO1.HTTPWebNode.Agent := 'Borland SOAP 1.2';
    HTTPRIO1.HTTPWebNode.UseUTF8InHeader := true;
    Iservice:= HTTPRIO1 as Service1Soap;
   //______________

uid:=euid.Text;
        pwd:=epwd.Text;
        mob:=emobno.Text;
       txt:=econtent.Text;

back_info:=Iservice.SendMessages(uid,pwd,mob,txt,'');
           memo2.Text:=back_info;
        if length(trim(back_info))>3 then begin
            showmessage('短信发送成功'+back_info);
        end else begin
           showmessage('短信发送失败'+back_info);
        end;
end;

注:

initialization
  InvRegistry.RegisterInterface(TypeInfo(Service1Soap), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service1Soap), 'http://tempuri.org/%operationName%');
     //delphi调用net2.0需要加这一行。否则会出错。
    InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap), ioDocument);

end.

JAVA示例:

需要导入axis.jar

package server;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URLConnection;
import java.net.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class smsService {
 
 private String getSoapSmssend(String userid,String pass,String mobiles,String msg,String time)
    {
        try
        {
            String soap = "";
            soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
              +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
              +"<soap:Body>"
              +"<SendMessages xmlns=\"http://tempuri.org/\">"
              +"<uid>"+userid+"</uid>"
              +"<pwd>"+pass+"</pwd>"
              +"<tos>"+mobiles+"</tos>"
              +"<msg>"+msg+"</msg>"
              +"<otime>"+time+"</otime>"              
              +"</SendMessages>"
              +"</soap:Body>"
              +"</soap:Envelope>";                       
            return soap;
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return null;
        }
    }
 
  
 private InputStream getSoapInputStream(String userid,String pass,String mobiles,String msg,String time)throws Exception
    {
  URLConnection conn = null;
  InputStream is = null;
        try
        {
            String soap=getSoapSmssend(userid,pass,mobiles,msg,time);           
            if(soap==null)
            {
                return null;
            }
            try{
            
             URL url=new URL("http://URL/Service.asmx");    
             
             conn=url.openConnection();
             conn.setUseCaches(false);
                conn.setDoInput(true);
                conn.setDoOutput(true);                          
                conn.setRequestProperty("Content-Length", Integer.toString(soap.length()));
                conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
                conn.setRequestProperty("HOST","URL");
                conn.setRequestProperty("SOAPAction","\"http://tempuri.org/SendMessages\"");

OutputStream os=conn.getOutputStream();
                OutputStreamWriter osw=new OutputStreamWriter(os,"utf-8");
                osw.write(soap);
                osw.flush();               
            }catch(Exception ex){
             System.out.print("SmsSoap.openUrl error:"+ex.getMessage());
            }                                           
            try{
             is=conn.getInputStream();             
            }catch(Exception ex1){
             System.out.print("SmsSoap.getUrl error:"+ex1.getMessage());
            }
           
            return is;  
        }
        catch(Exception e)
        {
         System.out.print("SmsSoap.InputStream error:"+e.getMessage());
            return null;
        }
    }
 
 //发送短信
 public String sendSms(String userid,String pass,String mobiles,String msg,String time)
    {
        String result = "-12";
  try
        {
            Document doc;
            DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db=dbf.newDocumentBuilder();
            InputStream is=getSoapInputStream(userid,pass,mobiles,msg,time);
            if(is!=null){
             doc=db.parse(is);
             NodeList nl=doc.getElementsByTagName("SendMessagesResult");
             Node n=nl.item(0);
             result=n.getFirstChild().getNodeValue();
             is.close();
            }             
            return result;
        }
        catch(Exception e)
        {
         System.out.print("SmsSoap.sendSms error:"+e.getMessage());
            return "-12";
        }
    }

}

PHP示例:

<?php
$uid = "账号";//用户账户
$pwd = "密码";//用户密码
$mobno = "手机号码";//发送的手机号码,多个请以英文逗号隔开如"138000138000,138111139111"
$content = "发送内容";//发送内容
$otime = '';//定时发送,暂不开通,为空
$client = new SoapClient("URL/Service.asmx?WSDL");
$param = array('uid' => $uid,'pwd' => $pwd,'tos' => $mobno,'msg' => $content,'otime'=>$otime);
$result = $client->__soapCall('SendMessages',array('parameters' => $param));
var_dump($result);
die();
?>

VB.NET示例:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim objSoap As Object, url As String
        url = "URL/Service.asmx?wsdl"
        objSoap = CreateObject("MSSOAP.SOAPClient30")
        objSoap.ClientProperty("ServerHTTPRequest") = True
        objSoap.MSSoapInit(url)

txtReturn.Text = objSoap.SendMessages(txtName.Text, txtPwd.Text, txtPhone.Text, txtContent.Text, "")

End Sub

VB示例:

Private Sub Command1_Click()

Dim mySoap As New MSSOAPLib30.SoapClient30
mySoap.ClientProperty("ServerHTTPRequest") = True
mySoap.MSSoapInit "URL/Service.asmx?WSDL"
txtReturn.Text = mySoap.SendMessages(txtName.Text, txtPwd.Text, txtPhone.Text, txtContent.Text, "")
Set mySoap = Nothing

End Sub

VC示例:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

TService:: Service1 ^v = gcnew TService:: Service1;//添加Web引用
    
     txtReturn ->Text = v -> SendMessages(txtName ->Text,txtPwd->Text,txtPhone->Text,txtContent->Text,"");
    }
 };

各种开发语言示例调用WebService接口的更多相关文章

  1. 各种开发语言示例调用HTTP接口(示例中默认HTTP接口编码为gb2312)

    asp示例: function getHTTPPage(strurl,data)   on error resume next   set http = Server.CreateObject(&qu ...

  2. python开发笔记-python调用webservice接口

    环境描述: 操作系统版本: root@9deba54adab7:/# uname -a Linux 9deba54adab7 --generic #-Ubuntu SMP Thu Dec :: UTC ...

  3. php中创建和调用webservice接口示例

    php中创建和调用webservice接口示例   这篇文章主要介绍了php中创建和调用webservice接口示例,包括webservice基本知识.webservice服务端例子.webservi ...

  4. Java调用webservice接口方法

                             java调用webservice接口   webservice的 发布一般都是使用WSDL(web service descriptive langu ...

  5. js调用Webservice接口案例

    第一步:新建Webservice接口 主文件方法 using System;using System.Collections.Generic;using System.Web;using System ...

  6. 动态调用WebService接口的几种方式

    一.什么是WebService? 这里就不再赘述了,想要了解的====>传送门 二.为什么要动态调用WebService接口? 一般在C#开发中调用webService服务中的接口都是通过引用过 ...

  7. ThinkPHP使用soapclient调用webservice接口

    1,开启 php.ini 这2个服务 12 extension=php_openssl.dllextension=php_soap.dll 以公共天气预报webservice为例,采用thinkPHP ...

  8. 使用soapui调用webservice接口

    soapui是专门模拟调用webservice接口的工具,下面介绍下怎么使用: 1.下载soapui并安装: 2.以免费天气获取接口为例:http://www.webservicex.net/glob ...

  9. 使用JS调用WebService接口

    <script> $(document).ready(function () { var username = "admin"; var password = &quo ...

随机推荐

  1. winform窗体——布局方式

    一.默认布局 ★可以加panel,也可以不加: ★通过鼠标拖动控件的方式,根据自己的想法布局.拖动控件的过程中,会有对齐的线,方便操作: ★也可选中要布局的控件,在工具栏中有对齐工具可供选择,也有调整 ...

  2. 火星02坐标转换为WGS84坐标

    import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import jav ...

  3. SQL Server查看所有表大小,所占空间

    create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),index_ ...

  4. ASP.NET内置对象

    ASP.NET中有六个内置对象 Response:向客户端输出信息或设置客户端输出状态. Request:获取客户端信息. Server:访问服务器的方法和属性. Application:用于将信息保 ...

  5. SetTimer and CreateWaitableTimer的例子(静态函数设置为回调函数,瑞士的网页,有点意思)

    Timers (SetTimer and CreateWaitableTimer) in Windows   SetTimer The following example creates a time ...

  6. Delphi 的各种错误信息(中英文)

    ******************************* * 编 译 错 误 信 息 * ******************************* ';' not allowed befo ...

  7. Ehcache中配置详解

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...

  8. Vi的几种退出方式

    1.q 退出 2.w 保存,继续操作 3.wq 保存退出 4.q! 不保存,放弃修改 5.x 同wq相似,但又有区别 wq   强制性写入文件并退出.即使文件没有被修改也强制写入,并更新文件的修改时间 ...

  9. 科研论文提交流程与常见问题(EDAS 系统提交)

    第一步 注册文章(Registering your Paper) 如上图,点击菜单中的submit paper按钮,会列出所有的会议和期刊,选择一个你要投稿的期刊或者会议,例如选择第一个2013 IE ...

  10. HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)

    Problem Description The International Clown and Pierrot Competition (ICPC), is one of the most disti ...