Using Web Service as a Data Source in Sql Server Reporting Services


Suppose this is a simple web method inside a web service in ASP.NET.

[WebMethod]

public string HelloWorld(String FirstName, String LastName) {

return “Hello “ + FirstName+ ” “ + LastName ;

}

Now we would to add the above as a xml data source in out Report.

For this we need to do the following

  • Create a new Report
  • Select <New DataSet..>
  • For Type (inside General Tab) select XML as DataSource type.
  • Inside connection string give the path to the web service.
  • i.e. http://localhost:2584/WebSites/Service.asmx
  • Define query for the data source in the following manner

<Query>

<Method Namespace=http://tempuri.org/ Name=HelloWorld>

</Method>

<SoapAction>http://tempuri.org/HelloWorld</SoapAction>

</Query>

 

We can create report parameters for FirstName and LastName parameters of the method.

Or we want to define default values for these parameters define the query as following

 

<Query>

<Method Namespace=http://tempuri.org/ Name=HelloWorld>

<Parameters>

<Parameter Name=FirstName>

<DefaultValue>Nishant</DefaultValue>

</Parameter>

<Parameter Name=LastName>

<DefaultValue>Rana</DefaultValue>

</Parameter>

</Parameters>

</Method>

<SoapAction>http://tempuri.org/HelloWorld</SoapAction>

</Query>

 

Bye..

Customizing Default IE Test Page for ASP.NET web service


Hi,

When we create ASP.NET web service from visual studio and run the web service a test page opens up in which we can test our web service.

We can easily customize that web service test page. The name of the page is DefaultWsdlHelpGenerator.aspx we can found it in the following directory

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\ for ASP.NET 2.0.

Open the page in Visual Studio

First and foremost we would find the following things that could be configured

// set this to true if you want to see a POST test form instead of a GET test form
bool showPost = true;

// set this to true if you want to see the raw XML as outputted from the XmlWriter (useful for debugging)
bool dontFilterXml = false;

// set this higher or lower to adjust the depth into your object graph of the sample messages
int maxObjectGraphDepth = 4;

// set this higher or lower to adjust the number of array items in sample messages
int maxArraySize = 2;

// set this to true to see debug output in sample messages
bool debug = false;

To customize the UI good information is provided over here

Customizing Web Service Test Page’s UI Design

By Default the web service can be tested using Http Get (default) and Http Post, but if we want to test using the SOAP we can make use of the information provided in the following link

Testing Web Service with SOAP

Bye

Consuming an Asp.NET web service using SOAP protocol from JavaScript


There are many ways we can consume a web service
The three common protocols for accessing a .NET web service are
HTTP GET, HTTP POST and SOAP.
The trasport protocol used for them is HTTP. However a web sercie can work on any other internet protocol like SMTP, FTP, Jabber, and TCP.

For HTTP GET and HTTP POST method you can refer to these posts
https://nishantrana.wordpress.com/2007/10/22/calling-aspnet-web-service-from-javascript-ajax-passing-parameter/
https://nishantrana.wordpress.com/2007/10/22/calling-aspnet-web-service-from-javascript-ajax-passing-parameter-post/
The proxy class generated by Visual studio for us using the wsdl itself uses the SOAP.
Let’s take an example of calling the simple web service using SOAP through java script.
Say this is our sample web service

[WebService(Namespace = “http://myNamespace/&#8221;)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld(String name) {
return “Hello “+name;
}

}

The javascript code that we can use to call this web service using SOAP request would be this
<script type=”text/javascript”>
var xmlHttp;
function SoapCall()
{
// creatng the xmlHttp object
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
// Calling the web service using post and true means asynchronous call
xmlHttp.open(“post”, “http://localhost/WebSite/WebSite4/Service.asmx&#8221;, true);
// Setting the request header to let the web service identify the soap request we would be sending
xmlHttp.setRequestHeader(“Content-Type”,”text/xml; charset=utf-8″);
// http://myNamespace/HelloWorld – name of the webmethod
//[WebService(Namespace = “http://myNamespace/&#8221;)] which we had applied to our web service class
xmlHttp.setRequestHeader(“SOAPAction”,”http://myNamespace/HelloWorld&#8221;);
xmlHttp.onreadystatechange=doUpdate;
// setting the soap request body
var soapRequest=”<?xml version=’1.0′ encoding=’utf-8′?>” +
“<soap:Envelope xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance'”+
” xmlns:xsd=’http://www.w3.org/2001/XMLSchema&#8217; xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/’>”+
“<soap:Body>”+
“<HelloWorld xmlns=’http://myNamespace/’>”+
“<name>Nishant Rana</name> “+
“</HelloWorld>”+
” </soap:Body>”+
“</soap:Envelope>”;


xmlHttp.send(soapRequest);
return false;


}

function doUpdate()
{
debugger;
if(xmlHttp.readyState==4)
{
var responseXMLResult=xmlHttp.responseXML;
var result = responseXMLResult.lastChild.nodeTypedValue;
alert(result);
}
}
</script>

We will receive the following Soap Response
<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt;
<soap:Body>
<HelloWorldResponse xmlns=”http://myNamespace/”&gt;
<HelloWorldResult>Hello Nishant Rana</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>

We can create our SOAP request by making use of the test page of our Web Service which we can open in IE.

Or else we can use Fiddler tool. (http://www.fiddlertool.com/fiddler/)

Bye..

Unable to generate a temporary class (result=1). error CS2001: Source file ‘C:\WINDOWS\TEMP\filename.cs’ could not be found error CS2008: No inputs specified


Hi,

I was getting this error when I was trying to call a .NET dll from an ASP page.

The dll was making use of a web service.

And while searching for it I found that if we are making use of a web service from

an asp page, the page tries to create a temporary file in windows\temp directory and because it hasn’t got rights for the same we get the error.

 

We can resolve it by giving it the appropriate rights for the windows/temp folder

 

1) Right click the temp folder à Select properties

2) Go to security tab

3) Click on Add and add ASPNET account. ( In locations select your machine )

4) Then add one more account IWAM_D-0824 (i.e. IWAM_YourMachineName)

5) Try running the ASP page again. The page should run without any error.

Bye

Using Forms Authentication in Asp.NET


Hi All,

To use form authentication in asp.net application

1- Create a new website

2- Change the name of the default.aspx to login.aspx

3- Add 2 labels one for username and password and two textboxes name txtUserName and txtPassword

and a button named btnLogin with label Login.

4 -Put the following in the web.config page

<authentication mode=”Forms”>
<forms loginUrl=”login.aspx”>
<credentials passwordFormat=”Clear”>
<user name=”Mickey” password=”Mouse”/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users=”?”/>
</authorization>

5-Put this code in the btnLogin click’s event handler.

protected void btnLogin_Click(object sender, EventArgs e)
{
if(FormsAuthentication.Authenticate(txtUserName.Text,txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
}
else
{
lblInfo.Text = “you are not authorized to view the page”; // add one more label lblInfo }
}

6- That’s it your page should work now

We can add more users within the credential section of web.config

We can even encrypt the password we are saving in the web.config

We can even make use of cookie for the same.

Looking forward to include the code for the same

Bye

%d bloggers like this: