Web サービスの結果を取得するために、次のことを試しました。
<%
Dim oRequest
Set oRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
oRequest.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
oRequest.setTimeouts 10000, 10000, 10000, 10000
msURL = "http://[0.0.0.0]/contale/customer.asmx/GetInfoFromWhitesPages"
msSOAP = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
msSOAP = msSOAP & "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">"
msSOAP = msSOAP & "<s:Body>"
msSOAP = msSOAP & "<GetInfoFromWhitesPagesResponse xmlns=""http://[0.0.0.0]/Contale/"">"
msSOAP = msSOAP & "<phone>4504656253</phone>"
msSOAP = msSOAP & "</GetInfoFromWhitesPagesResponse>"
msSOAP = msSOAP & "</s:Body>"
msSOAP = msSOAP & "</s:Envelope>"
oRequest.Open "POST", msURL, False
oRequest.setRequestHeader "Content-Type", "text/xml"
oRequest.setRequestHeader "SOAPAction", "[Some Url]"
oRequest.send msSOAP
Response.Write oRequest.ResponseBody
%>
しかし、結果は以下を示しています: ????????????????›???4?????????????????????????? †???????????????????????????????????†?4??????????? ????????????????????????
私も次のことを試しました:
<html>
<head><title></title></head>
<body>
<%
Dim objHTTP, strEnvelope
Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"
strEnvelope = strEnvelope & "<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/'>"
strEnvelope = strEnvelope & "<soap:Body>"
strEnvelope = strEnvelope & "<GetInfoFromWhitesPagesResponse xmlns='http://[0.0.0.0]/Contale'>"
strEnvelope = strEnvelope & "<phone>4504656253</phone>"
strEnvelope = strEnvelope & "</GetInfoFromWhitesPagesResponse>"
strEnvelope = strEnvelope & "</soap:Body></soap:Envelope>"
Dim url
url = "http://[0.0.0.0]/contale/customer.asmx"
With objHTTP
.Open "post", url, False
.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
.setRequestHeader "SOAPAction", "http://[0.0.0.0]/contale/GetInfoFromWhitesPagesResponse"
.send strEnvelope
End With
Dim strResponse
strResponse = objHTTP.responseXML.Text
If (strResponse = "") Then
Response.Write("Invalid user")
Else
Response.Write(strResponse)
End If
%>
</body>
</html>
しかし、私はこれを得ています:
soap:ClientSystem.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://[0.0.0.0]/contale/GetInfoFromWhitesPagesResponse. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
これが私のWebServiceのコードです:
using System;
using System.Net;
using System.Text.RegularExpressions;
using System.Web.Services;
namespace CustomersInfo
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://[0.0.0.0]/Contale/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public CustomerData GetInfoFromWhitesPages(string phone)
{
var customer = new CustomerData();
var webClient = new WebClient();
webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 Other");
var content = webClient.DownloadString("http://www.whitepages.com/phone/" + phone);
const string infoStart = "<div class=\"address-card\">";
if (content.Contains(infoStart))
{
var startPos = content.IndexOf("<div class=\"address-card\">", StringComparison.Ordinal) + infoStart.Length;
var endPos = content.IndexOf("</div>", startPos, StringComparison.Ordinal);
var info = content.Substring(startPos, endPos - startPos).TrimEnd().TrimStart();
info = info.Replace("\n", "").Replace("<p>", "").Replace("</p>", "");
string[] tabInfo = Regex.Split(info, "<br />");
string name = tabInfo[0];
string address = tabInfo[2];
string city = tabInfo[3].Split(' ')[0].Replace(",", "");
string province = tabInfo[3].Split(' ')[1];
string zip = tabInfo[3].Split(' ')[2] + " " + tabInfo[3].Split(' ')[3];
customer.Name = name;
customer.Address = address;
customer.City = city;
customer.Province = province;
customer.Zip = zip;
}
return customer;
}
public struct CustomerData
{
public string Name;
public string Address;
public string City;
public string Province;
public string Zip;
}
}
}
どんな助けでも大歓迎です。
ありがとうございました