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. uboot的devices_init函数分析

    一.函数说明 函数功能: 完成设备的初始化 函数位置: common/devices.c 二.程序分析 int devices_init (void) { #ifndef CONFIG_ARM /* ...

  2. Zephyr-MQTT

    Zephyr OS 支持MQTT协议,其源码目录在: # cd /zephyr-/samples/net/paho_mqtt_clients/publisher/ # cd /zephyr-1.5.0 ...

  3. 转:Windows下的PHP开发环境搭建——PHP线程安全与非线程安全、Apache版本选择,及详解五种运行模式。

    原文来自于:http://www.ituring.com.cn/article/128439 Windows下的PHP开发环境搭建——PHP线程安全与非线程安全.Apache版本选择,及详解五种运行模 ...

  4. 【技术贴】解决前台js传参中文乱码

    方法1: 前台两次编码,后台一次解码.因为getParamet已经自动解了一次了. JavaScript: window.self.location="list.jsp?searchtext ...

  5. 辉哥用的这种方法实现ZABBIX的MYSQL批量监控

    不错的.集中和分布式,总是一对要解决的问题.应该可以再想更好的策略~~ 一.方案需求及思路 因跑MySQL服务的服务器比较多,并且每台服务器可能会运行多个不同端口的数据库,如果单独手动一台一台去修改a ...

  6. C#程序设计基础——类、对象、方法

    类与对象 类 类是一种构造,通过使用该构造,用户可以将其他类型的变量.方法和事件组合在一起,从而创建自定义类型.类就像一个蓝图,它定义类型的数据和行为. 对象 定义类之后,便可通过将类加载到内存中来使 ...

  7. c# 哈希表集合;函数

    * 哈希表集合 1.先进去的后出来,最后进去的先出来 2.利用枚举类型打印出集合中的Key值和Value值 ** 函数 1.函数:能够独立完成某项功能的模块. 函数四要素:输入.输出.函数体.函数名 ...

  8. android 读取SD卡文件

    SD卡作为手机的扩展存储设备,在手机中充当硬盘角色,可以让我们手机存放更多的数据以及多媒体等大体积文件.因此查看SD卡的内存就跟我们查看硬盘的剩余空间一样,是我们经常操作的一件事,那么在Android ...

  9. strtotime的几种用法区别

    strtotime不仅可以使用类似Y-m-d此类标准的时间/日期字符串来转化时间戳, 还可以用类似自然语言的来生成时间戳, 类似: strtotime('last day'); strtotime(' ...

  10. Linux Kernel 空指针逆向引用拒绝服务漏洞

    漏洞名称: Linux Kernel 空指针逆向引用拒绝服务漏洞 CNNVD编号: CNNVD-201306-449 发布时间: 2013-07-01 更新时间: 2013-07-01 危害等级:   ...