Tải bản đầy đủ - 0 (trang)
Chapter 25. How to Use Reporting Services Web Services

Chapter 25. How to Use Reporting Services Web Services

Tải bản đầy đủ - 0trang

Chapter25.HowtoUseReporting

ServicesWebServices

InThisChapter

ReportManagementWebServiceNewin2005

(ReportService2005.asmx)

HowtoScriptReportingServices(UsingtheRSUtility)

WorkingwithReportParameters

SecurityWhenCallingaWebService

SomeoftheCommonlyUsedMethodswithShortCode

Snippets

Inthepreviouschapter,youlearnedaboutURLAccess

functionality.URLAccessprovidedhigh-performanceaccessto

SSRSforreportviewingandnavigation.However,URLAccess

doesnotprovidesufficientaccesstoSSRS'management

functionality.SSRS'webservicescomestotherescueand

complementsURLAccessbyprovidingfullaccesstoSSRS'

managementandrenderingfunctionality.

Anapplicationthatneedstoincorporatebothreportviewing

andreportmanagementfunctionalitywouldtypicallyuseboth

URLAccessandtheSSRSwebservice.Combiningthetwois

usedforacoupleofreasons:URLAccessprovidesthebest

performanceforthereportviewingexperienceandhandles



framingofareport;incontrast,SSRSwebserviceprovides

comprehensiveaccesstoSSRSfunctionality,including

managementfunctionality,whichisnotavailableinURLAccess.

BecausethewebserviceemploysSimpleObjectAccessProtocol

(SOAP)overHTTP,anySOAP-awareapplicationordevelopment

toolscancommunicatewiththeSSRSwebservice.Technically,

youcanmanuallygenerateSOAPrequests(whicharebasically

XMLtextwrittentoSOAPspecifications)andpassthose

requeststotheSSRSwebservice.VisualStudiogeneratesa

webproxyandmakesusingawebserviceaseasyasusingany

.NETnamespace.

Let'sstartwithasimpleexample.Thisexamplewalksthrough

theuseoftheRender()functiontoaccesstheSSRSwebservice,

andthenincorporatestheresultingstreamintoacustom

application.Muchlikeparametercommandswiththesame

nameinURLAccess,Render()andListChildren()arethemost

frequentlyusedfunctionsintheSSRSwebservice.

Asanexample,let'screateasimplefunctionthatretrievesa

reportfromSSRS.Herearethesteps:

1. OpenVisualStudio2005.

2. CreateaC#projectandcallitEmbeddedReport.

3. RenameForm1thatVisualStudiocreatedtoMainForm.

4. AddareferencetotheReportingServiceswebserviceby

right-clickingontheprojectinSolutionExplorerand

selectingAddWebReferencefromtheshortcutmenu,orby

selectingAddWebReferencefromtheProjectmenu,asshownin

Figure25.1.



Figure25.1.AddingwebreferencesinVisual

Studio.

[Viewfullsizeimage]



5. Selectthemostappropriatehyperlinkorenter

http:///reportserver/ReportExecution2005?wsdlin

theURLfieldoftheAddWebReferencedialogboxandclick

GO.NoteisthenameofaserveronwhichReport

Serverisinstalled.Ifdevelopmentisperformedonthesame

machineonwhichReportServerisinstalled,selecttheWeb

ServicesontheLocalMachinehyperlink.AfterVisualStudio

completesthisoperation,itpresentsaselectionsuchasthe

oneshowninFigure25.2.



Figure25.2.Listofavailablewebservices.



[Viewfullsizeimage]



Figure25.2isatypicallistofwebservicesforacomputer

thatjusthastheReportingServiceswebservice.Thelist

mightbelongerifthereareanyadditionalwebservices

availableonacomputer.FourSSRS,whichareoutlinedin

Table25.1,webservices(orSSRSwebserviceendpoints)

areavailableinSSRS2005.



Table25.1.SSRS2005WebServices

Services



TypicalEndpointURL(SSRSInstalledonlocalhost)



Functionality



ReportExecution2005New http://localhost/ReportServer/ReportExecution2005.asmx Report

execution

in2005

endpoint

contains

functionality

tocontrol

report

processing

and

rendering.

Not

compatible



withSSRS

2000.

ReportService



http://localhost/ReportServer/ReportService.asmx



SSRS2000

backward

compatibility

interface.



ReportService2005New

in2005



http://localhost/ReportServer/ReportService2005.asmx



Reportand

server

management

endpoint.



Note

ToviewaWebServiceDescriptionLanguage(WSDL)

inabrowser,add?wsdlafteranyofSSRSendpoint's

URLs,suchas

http://localhost/ReportServer/ReportService2005.asmx?

wsdl.



6. Selectoneofthewebservices(SSRSendpoints)afterVisual

Studiocompletesthisoperation(webreferenceisfound).

7. ReplaceServerNamewithReportExecution2005intheWeb

ReferenceNametextbox.

8. ClickAddReference.



SolutionExplorernowdisplaysReportExecution2005asoneofthe

webreferences.TopermittheuseoftypesinReporting

Services,youneedtoaddawebproxyreferencetoeach



modulethatusesawebservice.Inageneralcase,thesyntax

ofthereferencelookslikethefollowing:



using<>.<


Inthisspecificexample,youadd:



usingEmbeddedReport.ReportExecution2005;

usingSystem.Web.Services.Protocols;//tohandleSOAPxceptions



ThesecondlineisaddedtohandleSOAPexceptions.

ThefollowingcodegeneratesXMLoutputforareport.Youcan

useotherformatssupportedbyrenderingextensions,suchas

HTML.



staticstringGetReportXML2005(stringReportingServicesURL,

stringReportPath)

{

//createsanewWebservice(proxy)andsetitscredentials

ReportExecutionServicers=newReportExecutionService();

//windowsauthentication



rs.Credentials=System.Net.CredentialCache.DefaultCredenti

//AssignWebserviceurl.Thisisoptionaloperation.Defau

//isassignedduringthecreationofaproxy.

//Typicallyhttp://<>/ReportServer/ReportExecu

rs.Url=ReportingServicesURL;

//SetupRender()call

byte[]result=null;

stringencoding,mimeType,extension;

Warning[]warnings=null;

string[]streamIDs=null;



try

{

//ShouldbecalledpriortoRender()tosetreport'spa

rs.LoadReport(ReportPath,null);



//GetsabytestreamwithCommaSeparatedValue(XML)l

result=rs.Render("XML",null,outextension,outenco

outmimeType,outwarnings,outstre

returnSystem.Text.Encoding.ASCII.GetString(result);

}

catch(SoapExceptione)

{

//Returnexceptionmessage,ifexceptionoccured

returne.Message;

}

}



AcalltoGetReportXML2005()belowdemonstratesanassignmentof

the/Samples/DemoListreportintheXMLformtoatextbox

textBoxResult:

textBoxResult.Text=GetReportXML2005(



"http://localhost/ReportServer/ReportExecuti

"/Samples/DemoList");



Note

IfyouwanttoincorporatetheresultsofRender()in

thewebapplication,youcanpassdeviceinformation



settingstoretrieveanHTMLfragmentthatdoesnot

containaBODYelement.Thecallwouldlooksimilar

tothefollowing:



result=rs.Render("HTML",

"True

",...);



Youmighthavenoticedthefollowingassignmentinthecode

rs.Url=ReportingServicesURL;thisisanoptionaloperationbecause

thewebproxyalreadyincorporatestheURLoftheserverfor

whichitwasgenerated.Thisassignmentisbeneficialtomake

thecodeportableandenableittoaccessanyspecifiedSSRS

webservice.

MostparametersintheRender()functionareoptionalandaccept

nullvalues.

Warning[]warnings;containsanarrayofobjectswithinformation



abouterrorsandwarningsforwhichSSRSdidnotgenerate

exceptions.Inproductioncode,youneedtomakesureto

incorporatehandlingforwarnings.

Thesampleusespartoftheinformationavailablein

SoapException.SoapExceptionhasfourproperties:

ActorThecodethatcausedexception.

DetailTheXMLdescribingapplication-specificerror



information.DetailisanXMLNodeobjectandinnertextfrom

Detailcanbeaccessedfortheflowcontrol,suchas



if(ex.Detail["ErrorCode"].InnerXml=="rsItemNotFound"){/*handle

theerror*/}.

HelpLinkAlinktoaHelpfileassociatedwiththeerror.

MesssageAmessagedescribingtheerror.



TheReportExecutionwebserviceisverysensitivetothe

report'spath,requiresthepathtostartfrom"/"(slash),and

doesnotacceptURL-encodedstrings.Ifthepathisincorrect,

webservicesreturnsanItemNotFoundExceptionexception.For

example,forareportwiththenameMyDemoList(notethespace

afterthewordMy)locatedintheSamplesdirectory,theURLencodedpath/Samples/My%20DemoListisnotacceptable.Itshould

causeanerrorwithanexceptionsimilartothefollowing:



System.Web.Services.Protocols.SoapException:Theitem'/Samples

cannotbefound.

--->Microsoft.ReportingServices.Diagnostics.Utilities.ItemNotF

Theitem'/Samples/My%20DemoList'cannotbefound.



SSRSwebservicecanraiseanotherexceptionforamissingor

incorrectpath:



System.Web.Services.Protocols.SoapException:

Thepathoftheitem""isnotvalid.

hepathmustbelessthan260characterslongandmuststartwi



Theproperwaytoenterthispathis/Samples/MyDemolist(noURL

encoding).



ActionsinGeTReportXML2005()shouldproducethesameresultas

http://localhost/ReportServer/ReportExecution2005.asmx?/Samples/Demo



Thedifferenceisthatthewebservicecallisnotinteractive,but

thewebservicecallallowsanapplicationtoreceiveandprocess

areport'sXMLinternally.

Theliners.Credentials=

System.Net.CredentialCache.DefaultCredentials;isveryimportant.An



applicationmustsupplycredentialstotheSSRSwebservice

beforeitcanaccessareport.DefaultCredentialsistheWindows

authenticationfortheuser.Lackofpropercredentialsresultsin

anexception:

Anunhandledexceptionoftype'System.Net.WebException'

occurredinsystem.web.services.dll.Additionalinformation:

herequestfailedwithHTTPstatus401:Unauthorized.



System.Text.Encoding.ASCII.GetStringisusedtoconvertabyte[]array



thatRender()returnstoastring.NotethatASCIIisanoption

suitablefortext-basedformats,suchasXMLandCSV.Other

converters(suchasUnicode)areavailableinthe

System.Text.Encodingnamespace.

IfyouareusingthisbooktoassessSSRS2000webservices,

youneedtokeepinmindthatReportingServices.asmxand

ReportService.asmxaretheonlyavailablewebservicesinthat

version.WebservicecallsignaturesinSSRS2000andSSRSare

notalwayscompatible.Forexample,theRender()methodin

SSRS2000has12parameters,whereasthesamemethodin

ReportExecution2005.asmxhas7parameters.TomakeaSSRS2000

stylecalltotheRender()method,youhavetoselect

ReportingServices.asmxandadditsreferenceinthecode(here,the

proxynameisReportingServices)asfollows:

usingEmbeddedReport.ReportingServices;



Then,youreplacetheinsideofatryblockwiththefollowing:

ParameterValue[]reportHistoryParameters=null;

result=rs.Render(ReportPath,"XML",

null,null,null,null,null,

outencoding,outmimeType,

outreportHistoryParameters,outwarnings,outstreamIDs);

returnSystem.Text.Encoding.ASCII.GetString(result);







Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 25. How to Use Reporting Services Web Services

Tải bản đầy đủ ngay(0 tr)

×