繁体   English   中英

如何获取对WebService请求使用自定义代理的C#WebService调用的结果?

[英]How to get the results of C# WebService call that used a custom proxy for the WebService request?

我正在尝试将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引用方法更新Web服务之后,一切都在公司网络以外但不在公司网络上正常工作。 SoapUI测试工具还可以保护防火墙。 但是,开源Wizdl C#.net工具确实可以从防火墙后面运行。

因此,这开始了对Wizdl工具(http://wizdl.codeplex.com/)进行反向工程以使其成为dll而不是Windows窗体应用程序的目标。 我认为各种各样的Access和Excel人员也希望拥有。

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

不知道这是否相关,但是当遇到无法直接针对我开发的安全Web服务时,我使用了Fiddler。

首先捕获wsdl文件(我想另一个),将它们另存为文本文件。 然后在Visual Studio在开发机器上更新服务期间要求Visual Studio对其进行“服务”时将其备份。

http://www.fiddler2.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM