private void Button1_Click(object sender, System.EventArgs e)
{
Add.Service Adds = new web.Add.Service();
int c = Adds.add(Convert.ToInt32(TextBox1.Text),Convert.ToInt32(TextBox2.Text));
Label1.Text=c.ToString();
/*截取处于开始字符串和结束字符串中间的字符串,尤其适合得到处于xml标签之间的字符串内容;
private string GetSubString(string mainString,string startString,string endString)
{
int start = mainString.IndexOf(startString);
int end = mainString.IndexOf(endString);
if (start<0||end<0)
{
return null;
}
else
{
string result = mainString.Substring(start+startString.Length,end-start-startString.Length);
return result;
}
}
其中mainString为子串,startString为起始标签,endString为结束标签.具体调用如下:
string start = "<Message>";
string end = "</Message>";
string mainString = WebServiceName.SendXml(parameter...);
string result = GetSubString(mainString,start,end);
然后用MessageBox显示出来,发短信的用户就知道是否发送成功了.
MessageBox.Show(result+"!");//加一个感叹号,漂亮一点:)
该资源的该问地址为:http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl,这是一个WSDL文件格式.
您可以直接在您的VS.NET环境中直接添加Web引用,把该地址输入即可。
该Web Service就只有一个方法,即string sendXml(carrier,userid,password,mobilenumber,content,msgtype)。
各个参数全部为string类型,其含义基本如下(可能不正确)。
carrier:运营商名称,这里面可以随便输,不过似乎没有任何显示,不知道里面有没有其它奥秘。
userid:您在新浪无线上注册的手机ID,即http://sms.sina.com.cn。
password:您在新浪无线上注册手机时所使用的密码。
mobilenumber:对方的手机号码;
content:发送短消息的内容;
msgtype:发送短消息的类型,我估计支持彩信,不过我目前仅使用文本短信方式,似乎随便输什么都可以,我使用的是“Text”。
*/
}
http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl
<?xml version="1.0" encoding="UTF-8" ?>
-
<
definitions name
="
SMSWS
"
targetNamespace
="
http://outlook.microsoft.com/add-ins/SMS/wsdl/
"
xmlns:wsdlns
="
http://outlook.microsoft.com/add-ins/SMS/wsdl/
"
xmlns:typens
="
http://outlook.microsoft.com/add-ins/SMS/type
"
xmlns:soap
="
http://schemas.xmlsoap.org/wsdl/soap/
"
xmlns:xsd
="
http://www.w3.org/2001/XMLSchema
"
xmlns:stk
="
http://schemas.microsoft.com/soap-toolkit/wsdl-extension
"
xmlns
="
http://schemas.xmlsoap.org/wsdl/
">
<
schema
targetNamespace
="
http://outlook.microsoft.com/add-ins/SMS/type
"
xmlns
="
http://www.w3.org/2001/XMLSchema
"
xmlns:SOAP-ENC
="
http://schemas.xmlsoap.org/soap/encoding/
"
xmlns:wsdl
="
http://schemas.xmlsoap.org/wsdl/
"
elementFormDefault
="
qualified
" />
</
types
>
-
<
message name
="
SMSWebService.sendXml
">
<
part
name
="
Carrier
"
type
="
xsd:string
" />
<
part
name
="
Id
"
type
="
xsd:string
" />
<
part
name
="
Password
"
type
="
xsd:string
" />
<
part
name
="
ToMobile
"
type
="
xsd:string
" />
<
part
name
="
Message
"
type
="
xsd:string
" />
<
part
name
="
MsgType
"
type
="
xsd:string
" />
</
message
>
-
<
message name
="
SMSWebService.sendXmlResponse
">
<
part
name
="
Result
"
type
="
xsd:string
" />
</
message
>
-
<
portType name
="
SMSWebServiceSoapPort
">
-
<
operation name
="
sendXml
"
parameterOrder
="
Carrier Id Password ToMobile Message MsgType
">
<
input
message
="
wsdlns:SMSWebService.sendXml
" />
<
output
message
="
wsdlns:SMSWebService.sendXmlResponse
" />
</
operation
>
</
portType
>
-
<
binding name
="
SMSWebServiceSoapBinding
"
type
="
wsdlns:SMSWebServiceSoapPort
">
<
stk:binding
preferredEncoding
="
UTF-8
" />
<
soap:binding
style
="
rpc
"
transport
="
http://schemas.xmlsoap.org/soap/http
" />
-
<
operation name
="
sendXml
">
<
soap:operation
soapAction
="
http://outlook.microsoft.com/add-ins/SMS/action/SMSWebService.sendXml
" />
<
soap:body
use
="
encoded
"
namespace
="
http://outlook.microsoft.com/add-ins/SMS/message/
"
encodingStyle
="
http://schemas.xmlsoap.org/soap/encoding/
" />
</
input
>
<
soap:body
use
="
encoded
"
namespace
="
http://outlook.microsoft.com/add-ins/SMS/message/
"
encodingStyle
="
http://schemas.xmlsoap.org/soap/encoding/
" />
</
output
>
</
operation
>
</
binding
>
-
<
service name
="
SMSWS
">
-
<
port name
="
SMSWebServiceSoapPort
"
binding
="
wsdlns:SMSWebServiceSoapBinding
">
<
soap:address
location
="
http://202.108.35.168/cgi-bin/ws/smswebservice0101
" />
</
port
>
</
service
>
</
definitions
>