37 |
private XmlRpcServiceInfo clientInfo; |
private XmlRpcServiceInfo clientInfo; |
38 |
private XmlRpcSerializer ser; |
private XmlRpcSerializer ser; |
39 |
private XmlRpcDeserializer dser; |
private XmlRpcDeserializer dser; |
40 |
|
private String header; |
41 |
public XmlRpcClientProtocol(IPHostEntry host) : base (host) |
public XmlRpcClientProtocol(IPHostEntry host) : base (host) |
42 |
{ |
{ |
43 |
|
|
45 |
|
|
46 |
public XmlRpcClientProtocol(MemberInfo type) : base(new IPHostEntry()) |
public XmlRpcClientProtocol(MemberInfo type) : base(new IPHostEntry()) |
47 |
{ |
{ |
48 |
|
String url = String.Empty; |
49 |
|
String port = String.Empty; |
50 |
|
String dest = String.Empty; |
51 |
Object[] attributes = type.GetCustomAttributes(typeof(XmlRpcUrlAttribute), false); |
Object[] attributes = type.GetCustomAttributes(typeof(XmlRpcUrlAttribute), false); |
52 |
XmlRpcUrlAttribute xmlrpcUrl = (XmlRpcUrlAttribute)attributes[0]; |
XmlRpcUrlAttribute xmlrpcUrl = (XmlRpcUrlAttribute)attributes[0]; |
53 |
String tmpUrl = xmlrpcUrl.Uri; |
String tmpUrl = xmlrpcUrl.Uri; |
54 |
int spot = tmpUrl.LastIndexOf("://")+3; |
int spot = tmpUrl.LastIndexOf("://")+3; |
55 |
tmpUrl = tmpUrl.Substring(spot, tmpUrl.Length - spot); |
tmpUrl = tmpUrl.Substring(spot, tmpUrl.Length - spot); |
56 |
spot = tmpUrl.IndexOf("/"); |
spot = tmpUrl.IndexOf("/"); |
57 |
|
dest = tmpUrl.Substring(spot, tmpUrl.Length-spot); |
58 |
tmpUrl = tmpUrl.Substring(0, spot); |
tmpUrl = tmpUrl.Substring(0, spot); |
59 |
spot = tmpUrl.IndexOf(":"); |
spot = tmpUrl.IndexOf(":"); |
60 |
String url = tmpUrl.Substring(0, spot); |
if(spot != -1) |
61 |
String port = tmpUrl.Substring(spot+1, tmpUrl.Length -spot -1); |
{ |
62 |
Console.WriteLine(url + " port " + port); |
// find port |
63 |
|
url = tmpUrl.Substring(0, spot); |
64 |
|
port = tmpUrl.Substring(spot+1, tmpUrl.Length -spot -1); |
65 |
|
} |
66 |
|
else |
67 |
|
{ |
68 |
|
port = "80"; |
69 |
|
url = tmpUrl; |
70 |
|
} |
71 |
|
header = "POST " + dest + " HTTP/1.0\nContent-Type: text/xml\nContent-Length: "; |
72 |
info = Dns.Resolve(url); |
info = Dns.Resolve(url); |
73 |
} |
} |
74 |
|
|
76 |
{ |
{ |
77 |
|
|
78 |
ser = new XmlRpcSerializer(); |
ser = new XmlRpcSerializer(); |
79 |
int state = Send( ser.SerializeRequest( request ).ToString() ); |
String requestXml = ser.SerializeRequest( request ).ToString(); |
80 |
|
int state = Send( requestXml ); |
81 |
if(state != -1) |
if(state != -1) |
82 |
{ |
{ |
83 |
XmlRpcResponse response = new XmlRpcResponse(receivedASCII); |
XmlRpcResponse response = new XmlRpcResponse(receivedASCII); |
95 |
return true; |
return true; |
96 |
} |
} |
97 |
|
|
98 |
public override int Send(String data) |
public int Send(String data) |
99 |
{ |
{ |
100 |
if(data == null) |
if(data == null) |
101 |
{ |
{ |
110 |
IPAddress[] ipaddress = info.AddressList; |
IPAddress[] ipaddress = info.AddressList; |
111 |
EndPoint ep = new IPEndPoint(ipaddress[0], 80); |
EndPoint ep = new IPEndPoint(ipaddress[0], 80); |
112 |
sock.Connect(ep); |
sock.Connect(ep); |
113 |
|
data = header + data.Length + "\n\n" + data; |
114 |
if(sock.Connected) |
if(sock.Connected) |
115 |
{ |
{ |
116 |
sock.Send(ASCII.GetBytes(data), ASCII.GetBytes(data).Length, 0); |
sock.Send(ASCII.GetBytes(data), ASCII.GetBytes(data).Length, 0); |