.net中的webservice代码
[WebMethod]
public int power(int a)
{ return a*a; }
客户端代码:
Private Sub Command_Click()
Dim Serializer As SoapSerializer30
Dim Reader As SoapReader30
Dim ResultElm As IXMLDOMElement
Dim FaultElm As IXMLDOMElement
Dim Connector As SoapConnector30
Const SoapAction = "http://tempuri.org/power"
Const END_POINT_URL = "http://localhost/NoWSE/Service1.asmx"
Set Connector = New HttpConnector30
Connector.Property("EndPointURL") = END_POINT_URL
Connector.Connect
Connector.Property("SoapAction") = SoapAction
Connector.BeginMessage
Set Serializer = New SoapSerializer30
Serializer.Init Connector.InputStream
Serializer.StartEnvelope
Serializer.StartBody
Serializer.startElement "power", "http://tempuri.org/"
Serializer.startElement "a"
Serializer.WriteString CStr(10)
Serializer.endElement
Serializer.endElement
Serializer.EndBody
Serializer.EndEnvelope
Connector.EndMessage
Set Reader = New SoapReader30
Reader.Load Connector.OutputStream
If Not Reader.Fault Is Nothing Then
MsgBox Reader.FaultString.Text, vbExclamation
Else
Text2.Text = Reader.RpcResult.Text
End If
End Sub
结果应该返回100啊,怎么返回0呢。查看soap请求也没什么错:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAPSDK4:power xmlns:SOAPSDK4="http://tempuri.org/">
<a>10</a>
</SOAPSDK4:power>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
为什么返回结果总是不对呢?
--
FROM 219.142.83.*