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. BZOJ 3572 世界树

    Description 世界树是一棵无比巨大的树,它伸出的枝干构成了整个世界.在这里,生存着各种各样的种族和生灵,他们共同信奉着绝对公正公平的女神艾莉森,在他们的信条里,公平是使世界树能够生生不息.持 ...

  2. 关于javascript

    Client-Language-----------------------JavaScript/Object-C/Java/C# HTML5 DOM/Template/Data/Ajax/Regul ...

  3. KV总结

    今天没事又重新写了一遍.很多注释是自己犯糊涂后来又终于跨过去的备忘. // ImgEff.js function ImgEff(div,time){ //构造函数,需要传入参数div的id和时间 // ...

  4. hdu 5147 Sequence II

    http://acm.hdu.edu.cn/showproblem.php?pid=5147 题意:问有多少个这样的四元组(a,b,c,d),满足条件是 1<=a<b<c<d; ...

  5. MFC任务管理器task manager----进程的挂起与恢复--NtSuspendProcess&&NtResumeProcess

    http://hi.baidu.com/xbbsh/blog/item/b73d3125462201084c088db1.html ---------------------------------- ...

  6. HDU 4717The Moving Points warmup2 1002题(三分)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. PGA突破pga_aggregate_target限制

    SQL> show parameter pga NAME         TYPE  VALUE ------------------------------------ ----------- ...

  8. 【拓扑】【宽搜】CSU 1084 有向无环图 (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1804 题目大意: 一个有向无环图(DAG),有N个点M条有向边(N,M<=105 ...

  9. 开源库CImg 数据格式存储之二(RGB 顺序)

    在上一篇博客中已经初步说明了GDI和CImg数据的存储格式感谢博友 Imageshop 评论说明 CImg的说明文档中已有详细说明(详见上篇博客说明) CImg的数据格式确实是RRRGGGBBB顺序存 ...

  10. entityframework分布式事务中遇到的 “与基础事务管理器的通信失败”的解决方法

    首先是ef的多数据库操作实现事务的方法 public int AddDifferenceDB(userinfo1 user1, userinfo user) { ; using (var test2D ...