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. Webservices-2.C#创建web服务,及引用访问、代码访问

    注:web服务简介Webservices-1.web服务定义简介 以下均以C#语言为例 一.创建web服务(简单介绍,主要讨论客户端引用) 打开VS创建网站项目,在网站项目中添加“WEB服务(ASMX ...

  2. C#后台找不到前台html标签

    没关系!   只要他在form表单里  , 咱在标签加上一个   runat="server"就可以在后台cs代码里找到他了

  3. Unity3D Quaternion各属性和函数测试

    Quaternion属性与方法 一,属性: x.y.z就不说了,只看一个eulerAngles,代码如下: public Quaternion rotation = Quaternion.identi ...

  4. BZOJ 1035 Risk

    Description 经过连续若干年的推广,Risk这个游戏已经风靡全国,成为大众喜闻乐见的重要娱乐方式.Risk这个游戏可以理解为一种简易的策略游戏,游戏者的目的是占领所有的土地.由于游戏规则的规 ...

  5. 五种I/O 模式——阻塞(默认IO模式),非阻塞(常用语管道),I/O多路复用(IO多路复用的应用场景),信号I/O,异步I/O

    五种I/O 模式——阻塞(默认IO模式),非阻塞(常用语管道),I/O多路复用(IO多路复用的应用场景),信号I/O,异步I/O 五种I/O 模式:[1]        阻塞 I/O          ...

  6. bzoj2789

    这种题目肯定是先把一个当做标准串根据标准串得出一个初始串是怎么排列的,然后求逆序对数就可以了但是因为有重复,我们不知道标准串中的一个数到底是由原来哪个字母交换来的但是我们可以猜,不难贪心得到对于标准串 ...

  7. POJ 2289 Jamie's Contact Groups(多重匹配+二分)

    题意: Jamie有很多联系人,但是很不方便管理,他想把这些联系人分成组,已知这些联系人可以被分到哪个组中去,而且要求每个组的联系人上限最小,即有一整数k,使每个组的联系人数都不大于k,问这个k最小是 ...

  8. CodeForces 592B

    题目链接: http://codeforces.com/problemset/problem/592/B 这个题目没啥说的,画图找规律吧,哈哈哈 程序代码: #include <cstdio&g ...

  9. Windows环境下python多版本配置方案

    系统环境 Windows,安装了msys2,windows和msys2都安装了python,且版本比较多,使用shell/bash聚合工具conemu64 配置方案 配置msys2环境用户目录下的.b ...

  10. JavaBean基础

    JavaBean的概念 JavaBean是一种可重复使用.且跨平台的软件组件.JavaBean可分为两种:一种是有用户界面(UI,User Interface)的JavaBean:还有一种是没有用户界 ...