1

我正在尝试将 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 Web 服务发生了变化,我们的 IT 部门也发生了变化。防火墙变了。因此,在使用 Web References 方法更新 Web 服务后,一切正常,当不在公司网络上但不在公司网络上时。SoapUI 测试工具也躲在防火墙后面。但是,Open Source Wizdl C# .net 工具确实在防火墙后面工作。

因此,这开始了对 Wizdl 工具 (http://wizdl.codeplex.com/ ) 进行逆向工程以作为 dll 而不是 Windows 窗体应用程序的目标。我认为各种各样的 Access 和 Excel 人也会喜欢。

当然,为了让它工作,我硬编码了几个方面(稍后会修复)。到目前为止,即使在网络上,我也已成功地将数据从 Bing Web 服务返回到对象!然而,我似乎无法进行最终转换或解析或转换,以便我可以将 dll 中的数据作为字符串输出。我是如此接近,因为我可以在本地调试器窗口中看到结果,但是到目前为止它们是不可返回的。

4

1 回答 1

0

不确定这是否相关,但是当面对我无法直接开发的安全 Web 服务时,我使用了 fiddler。

首先捕获 wsdl 文件(我认为是另一个),将它们保存为文本文件。然后,当 Visual Studio 在开发机器上的服务更新期间请求它们时,“服务”它们备份。

http://www.fiddler2.com

于 2013-07-25T13:46:51.427 回答