The website looked up some soapclient information.
The demo is as follows:
A. Client soapclient.php:
try {
Non-wsdl method Call WebService
$soap = new SoapClient (NULL, Array (
' Location ' = ' http://localhost/WebService/soapService.php ',
' uri ' = ' soapservice.php '));
Calling functions
$result 1 = $soap->addition (200, 160);
echo $result 1;
}
catch (SoapFault $e) {echo $e->getmessage ();}
catch (Exception $e) {echo $e->getmessage ();}
?>
Two. Service-side soapservice.php:
NON-WSDL Mode provides webservice (specifies the appropriate URI)
$server = new SoapServer (Null,array ("uri" = "soapservice.php"));
$server-SetClass ("Calculator");
$server-handle ();
Class Calculator
{
function addition ($num 1, $num 2) {
$result = $num 1+ $num 2;
Return "{$num 1} plus {$num 2} with the result". $result. "! ";
}
}
?>
If the server is written in PHP. This can be understood, the demo is also correct.
But if the server does not know what language is written in. How do I communicate with soapclient?
A third party provides a URL for the request:
Http://www.XXX.com/ipcam/soapservice
Reply to discussion (solution)
WSDL Required
The client is as follows:
$soap = new SoapClient ("http://www.XXX.com/ipcam/soapservice/math.wsdl");
$result 1 = $soap->addition (200, 160);
echo $result 1;
Same, as long as the other side has addition method, and the parameter format also conforms to the line
WSDL Required
The client is as follows:
$soap = new SoapClient ("http://www.XXX.com/ipcam/soapservice/math.wsdl");
$result 1 = $soap->addition (200, 160);
echo $result 1;
The third party does not provide WSDL. So can I use soapclient?
Same, as long as the other side has addition method, and the parameter format also conforms to the line
In addition to the PHP SoapClient method communication is not able to directly use HTTP request to complete the communication?
Note: The third party provides the structure of the SOAP message. The third-party feedback information is also the SOAP information structure.
The message structure of the soap is added to the HTTP request
xmlns:soap= "Http://www.w3.org/2001/12/soap-envelope"
soap:encodingstyle= "Http://www.w3.org/2001/12/soap-encoding" >
...
...
...
...
...
...
Didn't you say there is an example of. NET? Stick it out and look.
public static string client_version = "1.0.0"; Public Const string Def_soapaddr_withdigestauth = "Http://www.xxx.com/ipcam/soapservice"; Public Const string Def_soapaddr_withsessionidauth = "Http://www.xxx.com/ipcam/ssservice"; Public Const string def_soapaddr_action = "Http://www.xxx.com/Userservice/useroperation"; /* User Registration */public static int soapuserregistration (string equipno, string authcode, S Tring Version, String UserName, String Password, String ConfirmPassword, String Emailbox, String OEMID, String devicename, String deviceattr, StringBuilder bufretsoapconfigdata, int Maxretsoapconfigdatasize, ref soaperror_info infosoaperror) {int retvalue =-1; String strresponse = ""; /* Check Input parameters */if (OEMID = = "") {OEMID = "0"; } if (Version = = "") {Version = CLIEnt_version; } String strrandom = GetRandomStr32 (); Constructs the SOAP request information StringBuilder soap = new StringBuilder (); Soap. Append ("
"); Soap. Append ("
\ n "); Soap. Append ("
"); Soap. Append ("
"); Soap. Append ("
"); Soap. Append ("
+ Version +"
); Soap. Append ("
GBK
"); Soap. Append ("
userregistration
"); Soap. Append ("
" + strrandom + "
); Soap. Append ("
" + devicename + "
); Soap. Append ("
" + deviceattr + "
); Soap. Append ("
"); Soap. Append ("
" + OEMID + "
); Soap. Append ("
+ UserName +"
); soap. Append ("
+ Password +"
); soap. Append ("
+ ConfirmPassword +"
); soap. Append ("
" + Emailbox + "
); Soap. Append ("
"); Soap. Append ("
"); Soap. Append ("
"); Soap. Append ("
"); byte[] parambytes = Encoding.UTF8.GetBytes (soap. ToString ()); for (int j = 0; J < 2; J + +) {try {//initiate request URI URI = new Uri (Def_soapaddr_withdigestauth); HttpWebRequest webRequest = (HttpWebRequest) httpwebrequest.create (URI); String strPasswordMd5 = MD5 (Authcode); Webrequest.preauthenticate = true; NetworkCredential myCred = new NetworkCredential (Equipno, Authcode); Webrequest.credentials = myCred; Webrequest.method = "POST"; Webrequest.useragent = "fsoap/1.0"; Webrequest.contenttype = "Text/xml; Charset=utf-8 "; Webrequest.contentlength = Parambytes.length; Webrequest.expect = ""; Webrequest.keepalive = false; WEBREQUEST.HEADERS.ADD ("SOAPAction", def_soapaddr_action); Webrequest.timeout = Max_remote_service_timeouT WebRequest.ServicePoint.Expect100Continue = false; using (Stream Requeststream = Webrequest.getrequeststream ()) {requestStream.Write (param Bytes, 0, parambytes.length); } WebResponse WebResponse = Webrequest.getresponse (); Stream streamresponse = WebResponse.GetResponseStream (); using (StreamReader Mystreamreader = new StreamReader (Streamresponse, Encoding.UTF8)) { Strresponse = Mystreamreader.readtoend (); Close the Stream object. Mystreamreader.close (); Streamresponse.close (); Release the HttpWebResponse. WebResponse.Close (); if (strresponse! = "") {XmlDocument xml = new XmlDocument (); Xml. LOADXML (strresponse); XmlNode roOtnode = XML. selectSingleNode ("//wsresponse"); if (RootNode! = null) {XmlNode node_errorinfo = null; XmlNode node_code = null; XmlNode node_description = null; /* ErrorInfo */node_errorinfo = Rootnode.selectsinglenode ("ErrorInfo"); if (node_errorinfo! = null) {Node_code = Node_errorinfo.s Electsinglenode ("Code"); if (Node_code! = null) {Infosoaperror.bufcode = Node_co De. InnerText; if (Infosoaperror.bufcode = = "0") {retvalue = 0 ; } else {RetValue =-2; }} node_description = Node_errorinfo.selectsinglenode ("Desc Ription "); if (node_description! = null) {Infosoaperror.bufdescrip tion = node_description.innertext; }}}} break; }} catch (System.Net.WebException webEx) {if (webex.response! = null) {if (Webex.status = = webexceptionstatus.timeout) { Continue } else {HttpStatusCode status = ((HttpWebResponse) Webex.resp Onse). StatusCode; int errvalue = ((int) status); RetValue = Errvalue; Continue }} else {retvalue =-1; Continue }} catch {RetValue =-1; Continue }} return RetValue; }
There are also definitions of variables, the function to get the value of the variable I will not post, too long, not affixed.