2012-11-17 42 views
1

我想讀取/轉換/解析成一個字符串WebService調用的結果。如何獲取使用WebService請求的自定義代理的C#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"; 

背景:

我需要更新我們創建通過COM調用從MS Access webservice的一個LatLongVerification DLL。直到幾個月前它正在工作。

但是,Bing Webservice發生了變化,IT部門也出現了變化。防火牆改變了因此,在使用Web引用方法更新Web服務之後,所有工作都可以使用,而不是在公司網絡上,而不是在公司網絡上。 SoapUI測試工具也保存在防火牆後面。然而,開源的Wizdl C#.net工具確實在防火牆後面工作。

因此,就此開始目標,以逆向工程Wizdl工具(http://wizdl.codeplex.com/)作爲DLL,而不是Windows窗體應用程序的工作。我認爲各種Access和Excel人員也會喜歡。

當然,在努力只得到它的工作,我已經硬編碼的幾個方面(稍後解決這個問題)。到目前爲止,我已經成功地將數據返回到了Bing Webservice的一個對象,即使在網絡上!然而,我似乎無法做最後的轉換或解析或轉換,以便我可以將字符串輸出到dll中的數據。我非常接近,因爲我可以在本地調試器窗口中看到結果,但迄今爲止它們不可退還。

+0

有沒有理由不只是使用「添加服務引用」? –

+0

我認爲這個選項和Web服務參考一樣。但是,在一些研究服務參考更新之後,它可能沒有防火牆問題。我會給它一個鏡頭。謝謝你的提示! – DavidsPilot

+0

不行,我再次使用新的服務引用方法OFF公司網絡(在測試模塊工作中需要棘手的服務參考)。但是,ON Corp Network服務被阻止。通過wireshark,它顯示了兩種更簡單的Web服務/服務方法,試圖通過TCP直接連接,與CustomProxy一樣,它使用HTTP/XML作爲通過Corp Firewall獲取的協議,但我無法讀取響應。 – DavidsPilot

回答

0

不知道這是相關的或沒有,但,當面對一個安全的Web服務,我無法直接開發針對我用小提琴手。

首先捕獲wsdl文件(我認爲另一個文件),將它們保存爲文本文件。 然後,當視覺工作室在開發機器上的服務更新期間請求它們時,「備份」它們。

http://www.fiddler2.com

相關問題