无法从 XML-RPC 读取响应
我目前正在使用 http://www.xml-rpc.net/ 中的 XML-
RPC我已经看到数百个从服务获取一个结果并将其存储在结构中的示例,但我需要存储“N”个值。
我会更好地解释它。我有一个源文件,基本上包含以下内容:
public struct estructura
{
public string apiKey;
}
[XmlRpcUrl("http://example.net/api/xmlrpc/thisfile.php")]
public interface IStateName : IXmlRpcProxy
{
[XmlRpcMethod("myserver.search.getSomething")]
XmlRpcStruct busqueda(estructura co);
}
我在 PageLoad 上还有一个带有此内容的 aspx 文件
protected void Page_Load(object sender, EventArgs e)
{
IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
try
{
estructura uno;
uno.apiKey = "My_API_Key_Value"; // Hidden for security reasons
XmlRpcStruct a = proxy.busqueda(uno);
}
catch (Exception ex)
{
Response.Write("Some error...");
}
}
这实际上有效,我正在使用 Fiddler 读取 HTTP 请求/响应,一切都很好,服务返回此...
HTTP/1.1 200 OK
Date: Tue, 01 Feb 2011 16:06:51 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Pragma: no-cache
Connection: close
XMLRPC-server: SimpleXMLRPC/0.7
Content-Length: 2177
Content-Type: text/xml; charset=UTF-8
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>ATEId</name>
<value>
<string>6</string>
</value>
</member>
<member>
<name>ATEDescripcionEsp</name>
<value>
<string>* No Especificado *</string>
</value>
</member>
</struct>
</value>
</param>
<param>
<value>
<struct>
<member>
<name>ATEId</name>
<value>
<string>10</string>
</value>
</member>
<member>
<name>ATEDescripcionEsp</name>
<value>
<string>Asociaciones de empresas</string>
</value>
</member>
</struct>
</value>
</param>
<param>
[The rest of params...]
</param>
</params>
</methodResponse>
我的问题是“var a”仅存储第一个“param”,我的意思是,我调试了代码,并且“a”仅包含这些条目
Name Value
["ATEDescripcionEsp"] "* No Especificado *"
["ATEId"] "6"
所以我只想存储所有结果(下一个结果应该是 ATEId=10 和 ATEDesripcionEsp="Asociaciones de Empresas") 来自服务器响应,或者,如果我不能这样做,我需要存储响应中的纯 XML,然后我将手动解析它。
I'm currently using XML-RPC from http://www.xml-rpc.net/
I've seen hundred of examples getting one result from the service and storing it in a struct, but I need to store "N" values.
I'll explain it better. I have a source file containing, basically this:
public struct estructura
{
public string apiKey;
}
[XmlRpcUrl("http://example.net/api/xmlrpc/thisfile.php")]
public interface IStateName : IXmlRpcProxy
{
[XmlRpcMethod("myserver.search.getSomething")]
XmlRpcStruct busqueda(estructura co);
}
I've also one aspx file with this on PageLoad
protected void Page_Load(object sender, EventArgs e)
{
IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
try
{
estructura uno;
uno.apiKey = "My_API_Key_Value"; // Hidden for security reasons
XmlRpcStruct a = proxy.busqueda(uno);
}
catch (Exception ex)
{
Response.Write("Some error...");
}
}
This actually works, I'm using Fiddler to read HTTP Requests/Responses and all is fine, the service returns this...
HTTP/1.1 200 OK
Date: Tue, 01 Feb 2011 16:06:51 GMT
Server: Apache/2.2.3 (CentOS)
X-Powered-By: PHP/5.1.6
Pragma: no-cache
Connection: close
XMLRPC-server: SimpleXMLRPC/0.7
Content-Length: 2177
Content-Type: text/xml; charset=UTF-8
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>ATEId</name>
<value>
<string>6</string>
</value>
</member>
<member>
<name>ATEDescripcionEsp</name>
<value>
<string>* No Especificado *</string>
</value>
</member>
</struct>
</value>
</param>
<param>
<value>
<struct>
<member>
<name>ATEId</name>
<value>
<string>10</string>
</value>
</member>
<member>
<name>ATEDescripcionEsp</name>
<value>
<string>Asociaciones de empresas</string>
</value>
</member>
</struct>
</value>
</param>
<param>
[The rest of params...]
</param>
</params>
</methodResponse>
My problem is that "var a" stores ONLY the first "param", I mean, I debugged the code and "a" contains only these entries
Name Value
["ATEDescripcionEsp"] "* No Especificado *"
["ATEId"] "6"
So I only want to store ALL results (next result should be ATEId=10 and ATEDescripcionEsp="Asociaciones de Empresas") from the server response or, If I can't do that, I need to store the plain XML from the response, then I would parse it manually.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在返回一组值。您可能需要考虑更改结构的架构以接受数组或使结构成为值数组。
It looks like you are returning a set of values. You may want to consider changing the schema of the structure to accept an array or make the struct an array of values.