One requirement is that you need to obtain a mobile phone home location and read a lot on the Internet.CodeI tried a lot of them, but it got stuck when I got to conn. setrequestmethod ("Post") and didn't study the specific problem. Then I checked the WebService that obtained the mobile phone's home location. Address:
Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx? WSDL
I wrote it myself and directly implemented it by calling WebService. The result is OK. It is simpler, but I don't know whether there are any drawbacks.
The following code is used:
Public ClassMobileservice
{
// Namespace
Public Final StaticStringNamespace= "Http://WebXml.com.cn /";
// Soapoption namespace + method name
Public Final StaticStringSoapoption= "Http://WebXml.com.cn/getMobileCodeInfo ";
// Methodname: name of the method to be called
Public Final StaticStringMethodname= "Getmobilecodeinfo ";
// Webserviceurl WebService address
Public Final StaticStringWebserviceurl= "Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx ";
// Define a soapobject object
PublicSoapobject request =Null;
PublicString getmobileaddress (string phoneno)
{
Request =NewSoapobject (Namespace,Methodname);
Request. addproperty ("mobilecode", phoneno); // Stored Procedure method parameters, parameter names andWebServiceThe order of parameter names must be consistent.
Request. addproperty ("userid ","");
Soapserializationenvelope envelope =NewSoapserializationenvelope (soapenvelope.Ver11);
Envelope. bodyout = request;
Envelope. DOTNET =True; // Specify to call. net
Httptransportse ht =NewHttptransportse (Webserviceurl);
Try
{
Ht. Call (Soapoption, Envelope );
}
Catch(Exception E)
{
E. printstacktrace ();
}
// Obtain data
Try
{
Object result = (object) envelope. getresponse ();
String STR = result. tostring ();
ReturnSTR; // result
}
Catch(Soapfault E)
{
Return Null;
}
}
}