2012-11-17 1 views
1

WebService 호출의 결과를 문자열로/cast/parse하려고합니다.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 액세스에서 웹 서비스를 호출하기 위해 만든 LatLongVerification DLL을 업데이트해야합니다. 몇 달 전까지 만해도 효과가있었습니다.

그러나 Bing Webservice가 변경되어 IT 부서가 담당합니다. 방화벽이 변경되었습니다. 따라서 Web References 메서드를 사용하여 Webservice를 업데이트 한 후 회사 네트워크가 아닌 회사 네트워크에서는 모든 것이 효과적이었습니다. SoapUI 테스트 도구는 방화벽 뒤에서도 작동합니다. 그러나 오픈 소스 Wizdl C# .net 도구는 방화벽 뒤에서 작동했습니다.

결과적으로 Wizdl 도구 (http://wizdl.codeplex.com/)를 리버스 엔지니어링하여 Windows 양식 응용 프로그램 대신 dll로 작업하는 것이 목표였습니다. 나는 엑세스와 엑셀의 다양한 사람들이 좋아할 것이라고 생각한다.

물론 작동시키기 위해 여러 측면을 하드 코딩했습니다 (나중에 수정 예정). 지금까지 네트워크에서도 Bing Webservice의 객체에 데이터를 성공적으로 반환했습니다! 그러나, 나는 문자열로 dll에 데이터를 출력 할 수 있도록 최종 캐스트 또는 구문 분석 또는 변환을 수행 할 수 없습니다. 너무 가까이서 현지 디버거 창에서 결과를 볼 수 있지만, 지금까지는 되돌릴 수 없습니다.

+0

"서비스 참조 추가"를 사용하지 않는 이유가 있었습니까? –

+0

그 옵션은 웹 서비스 참조와 같다고 생각했습니다. 그러나 일부 연구 서비스 참조 후 최신이고 아마도 방화벽 문제가 없을 수 있습니다. 나는 한 발을 내줄 것이다. 팁 주셔서 감사합니다! – DavidsPilot

+0

아니요. 새로운 서비스 참조 방법을 사용하여 OFF Corp 네트워크를 다시 작동 시켰습니다 (작동하려면 테스트 모듈에서 까다로운 서비스 참조가 필요했습니다). 그러나 ON Corp Network에서는 서비스가 차단됩니다. wireshark를 사용하면 TCP를 통해 직접 연결하려는 시도로서보다 쉬운 웹 서비스/서비스 방법 모두에 대해 보여줍니다. CustomProxy와 마찬가지로 Corp/Firewall을 통과하는 프로토콜로 HTTP/XML을 사용하지만 응답을 읽을 수 없습니다 . – DavidsPilot

답변

0

관련성이 있는지 여부는 모르지만 직접 개발할 수없는 보안 웹 서비스에 직면했을 때 필라를 사용했습니다.

먼저 wsdl 파일을 캡처하고 텍스트 파일로 저장하십시오. 그런 다음 dev 스튜디오에서 서비스를 업데이트하는 동안 Visual Studio에서 요청한 경우 다시 제공하십시오.

http://www.fiddler2.com