我正在尝试读取/转换/解析为WebService调用的结果的字符串。
WebMethod method = list.Services[0].Methods[0] as WebMethod;
if(method != null)
{
Object ResultsObj;
ResultsObj = new Object();
ResultsObj = method.Invoke();
//Returns "WS.GeocodeResponse" needs to be inner values
results = ResultsObj.ToString();
//Like to do the following but get error:
//'object' does not contain a definition for 'Results' and no extension
// method 'Results' accepting a first argument of type 'object' could be
// found (are you missing a using directive or an assembly reference?)
results = ResultsObj.Results[0].ToString();
//Or, do something like this but get same error
results = String.Format("Latitude: {0}, Longitude: {1}",
ResultsObj.Results[0].Locations[0].Latitude,
ResultsObj.Results[0].Locations[0].Longitude);
//Tried casting as an XmlDocument but get runtime error:
//{"Unable to cast object of type 'WS.GeocodeResponse' to type 'System.Xml.XmlDocument'."}
XmlDocument doc = new XmlDocument();
doc = (XmlDocument) method.Invoke();
results = "do something with doc";
//Tried looping through array of results but get error:
// The type or namespace name 'WS' could not be found (are you missing a using directive or an assembly reference?)
foreach(WS.GeocodeResult result in ResultsObj.GetType().Name)
{
continue;
}
//Tried reverse engineering what Visual Studio does when create Web Reference
//thanks to clue at http://www.west-wind.com/presentations/dotnetwebservices/DotNetWebServices.asp
// “That's because the proxy object is actually compiled into the project
//(take a look at \CodeClient\Web References\CodeWebService\CodeWebService.cs
// to see the source for this 'phantom' object that VS generates for you and compiles into your application.”
//Mine was "Project Name"/Web References/"Webservice Name"/Reference.cs
//I.E. ( LatLonVerification/Web References/net.virtualearth.dev/Reference.cs)
// Renamed it and added "using LatLonVerification.VirtualEarthGeo;" reference to it in this class;
//then finally tried to cast it to the new object type but got runtime error:
//{"Unable to cast object of type 'WS.GeocodeResponse' to type 'LatLonVerification.VirtualEarthGeo.GeocodeResponse'."} System.Exception {System.InvalidCastException}
GeocodeResponse geocodeResponse = (GeocodeResponse) ResultsObj;
results = "parse or do something with geocodeResponse";
背景:
我需要更新我们创建的LatLongVerification dll,以便通过com从MS Access调用Web服务。几个月前,它正在发挥作用。
然而,Bing Webservice发生了变化,我们的IT部门也陷入困境。防火墙改变了因此,在使用Web References方法更新Webservice之后,一切都有效,当离开公司网络但不在公司网络上时。 SoapUI测试工具也在防火墙后面保释。但是,开源Wizdl C#.net工具确实可以在防火墙后面工作。
因此,这开始了对Wizdl工具(http://wizdl.codeplex.com/)进行逆向工程以作为dll而不是Windows窗体应用程序工作的目标。我认为各种各样的Access和Excel人也会喜欢。
当然,为了让它发挥作用,我已经硬编码了几个方面(稍后会修复)。到目前为止,我已成功将数据从Bing Webservice返回到一个对象,即使在网络上!然而,我似乎无法进行最终的转换或解析或转换,以便我可以将dll中的数据作为字符串输出。我是如此接近,因为我可以在本地调试器窗口中看到结果,但到目前为止它们是不可退还的。
答案 0 :(得分:0)
不确定这是否相关,但是,当面对一个我无法直接开发的安全网络服务时,我使用了fiddler。
首先捕获wsdl文件(我想另一个),将它们保存为文本文件。 然后,当视觉工作室在开发机器上进行服务更新时请求它们“备用”它们。