I'm working on some application which is in ASP.Net 3.5 in which I've to embed a new feature called Instant Messaging/ Push Notification.
For this, I've used WCF to send data to client.
But the issue is, when WCF sends data to client at that time I'm unable to use it at client in asp page like I can't display it in web page or unable to update my page by using the data send by WCF.
I've tried
Response.Write(sendData); //sendData is the data which is send by WCF
just to write data on page,
But, Its also throwing an exception:
"Response is not available in this context."
So, please let me know how can I use sendData in my application.
You are trying to use HttpContext.Current.Response in a code where there is no current response.
If this is used in an HTTPHandler, you need to use the Context object passed through the ProcessRequest method in the IHTTPHandler interface.
Further, you can see here
Related
I am using ASP.NET 4.0 and need to return a SOAP (XML) Response to a JSON variable within javascript on the page. Than I would like to be able to call the variable and it's properties as you would with any JSON variable. The Soap Web Service (.asmx) file is not on the server where I need to build the client-side (receiving the request and putting it into a JSON variable). Also, to make this more complicated, the XML Request that gets send to the Web Service needs to send a UserName and Password to be able to return the items.
The URL for the Web Service is here: http://ws.idssasp.com/members.asmx?wsdl
Figured I would create a Visual Studio Web Application Project (C#), which I was able to do and connect to the Web Service just fine, however, This needs to be on a page that javascript uses to output the items that come from the methods of the web service. So, a .aspx file would not work in this case, since it would need to output only the result of the web service response in a JSON variable within a tag (probably in the head of the page, but doesn't matter to me where). Or it could dynamically create a .JS file (which would probably be better, since it would be cached and wouldn't need to call the web service multiple times if the js file exists on my server). However, I'm not sure on what to build in Visual Studio to accomplish this? And I'm not sure on how it would be used to output it onto the page. I suppose the JSON variable could also be stored within a Members.json file on the server and could just call that to load up the json needed.
How to return a JSON array from SOAP, XML, Response... after sending a request to another server with UserName and Password in the header of the SOAP Request. There is a page here that explains the XML needed for the Request and what the response will look like: http://ws.idssasp.com/members.asmx?op=GetMemberList&pn=0
On this same page, they show you how to do it via PHP, but PHP is not available, and only have ASP.NET 4.0 available to me. Here is their PHP way of doing it:
$clientWS = new SoapClient('http://ws.idssasp.com/Members.asmx?wsdl');
$namespaceWS = 'http://ws.idssasp.com/Members.asmx';
$dmsClientU = '';
$dmsClientP = '';
$headerBodyWS = array('UserName' => $dmsClientU, 'Password' => $dmsClientP);
$headerWS = new SOAPHeader($namespaceWS, 'AuthorizeHeader', $headerBodyWS, false);
$clientWS->__setSoapHeaders(array($headerWS));
$results = $clientWS->GetMemberList();
print_r( $results );
How would I be able to do the same thing here is ASP.NET 4.0, but instead of returning the XML result, return a JSON variable that gets used within a script tag on the page?
Or maybe I am overthinking this and there is a better solution?
If you are connecting to the web service and retrieving objects without issues, you should be able to construct JSON objects out of the properties of the SOAP responses.
I suggest creating a web service in ASP.NET, converting the SOAP response to JSON in the C# server code, then using AJAX in the JavaScript of your page to retrieve the JSON from your web service. Basically, you would be creating your own specialized conversion web service for your project that sits in the middle.
Keep the credentials you need server-side for your .asmx conversion service. Whatever you do, do not put credentials in the client-side JavaScript for a web service call, even if it lets you avoid writing server-side code.
For some reference on ASP.NET web services:
http://msdn.microsoft.com/en-us/library/bb398998%28v=vs.100%29.ASPX
http://msdn.microsoft.com/en-us/library/bb763183%28v=vs.100%29.ASPX
This is my first time developing this kind of system, so many of these concepts are very new to me. Any and all help would be appreciated. I'll try to sum up what I'm doing as efficiently as possible.
Background: I have a web application running AngularJS with Bootstrap. The app communicates with the server and DB through a web service programmed using C#. On the site, users can upload files and reference them later using direct links. There's no restriction to file type (yet), so just about anything is allowed.
My Goal: Having direct links creates a big security problem for me, since the documents/images are supposed to be private data. What I would prefer to do is validate a user's credentials when the link is clicked, then load the file in the browser using a more generic url path.
--Example--
"mysite.com/attachments/1" ---> (Image)
--instead of--
"mysite.com/data/files/importantImg.jpg"
Where I'm At: Not very far. My first thought was to add a page that sends the server request and receives a file byte stream along with mime type that I can reassemble and present to the user. However, I have no idea if this is possible using a web service that sends JSON requests, nor do I have a clue about how the reassembling process would work client-side.
Like I said, I'll take any and all advice. I'd love to learn more about this subject for future projects as well, but for now I just need to be pointed in the right direction.
Your first thought is correct, for it, you need to use the Response object, and more specifically the AddHeader and Write functions. Of course this will be a different page that will only handle file downloads, so it will be perfectly fine in your JSON web service.
I don't think you want to do this with a web service. Just use a regular IHttpHandler to perform the validation and return the data. So you would have the URL "attachments/1" get rewritten to "attachments/download.ashx?id=1". When you've verified access, write the data to the response stream. You can use the Content Disposition header to set the file name.
Hi I am new to the "SSRS" and web services i am trying to call the web service from the SSRS report.I have one web service which generates the barcode. I want the barcode to display in the report so i am calling the web service method from the ssrs.
The method is
[OperationContract]
Image BarcodeTextToImage(string value);
I am using the web service URL to call the method from the ssrs on the expression set to the image control as,
=Parameters!BarcodeURL.Value +"?value=" + CStr(Parameters!JobNumberFilter.Value)
where is BarcodeURL is set as
http://localhost/barcode/DataMatrix.svc/BarcodeTextToImage
but i am not getting any output and getting two warnings as ,
1) [rsInvalidImageReference] The Value for the image ‘Image3’ is invalid. Details: The remote server returned an error: (400) Bad Request.
2) [rsInvalidExternalImageProperty] The value of the ImageData property for the image ‘Image3’ is “”, which is not a valid ImageData.
Now i tried changing the config file of web service to change it to webHttpBinding still same issue. Any links and answers will be great.
I have got same problem some time back so i got a work around for this problem i hope this will work for you too.
1) First i created the web app with the service reference of the created web service suppose Barcode39 is service so add the reference to the web application.
2) Then write the code behind using service client and call the method to create the barcode image in that code by passing the request variables values
3) Now give the link of that page as the URL to the image expression along with setting the image type as "EXTERNAL" and pass the values to the URL as request variables as
"http:\\localhost:2310\BarcodeImage.aspx?data=" +(Parameters!YourParamtere.Value)
And one thing instead of returning the Image from the service try returning the byte array using stream and .ToArray() method that would be the best practice.Let me know if any problem.
I have a mobile application which I want to call a http post to pass a binary string and write it to a SQL Server. Can you please give me some examples of code in setting up a http post server (Server side code) to accept 2 values (brinary string & DeviveID string).
Any help, advice or links welcome....
I don't know the iPhone side, but from the C# side, you could either do it via HTTP GET variables (e.g. http://www.example.com/?string=foo&devive=bar) and handle your SQL in there.
You could also run a small program that has a listening Socket or TcpListener on whatever port you want, and then have a BeginRead() method active waiting for input from the iPhone app. Once the BeginRead() returns with some data, you could then handle your SQL.
You could create a WCF REST service for this (look up the WCF REST Starter Kit), but as a quick-and-dirty solution you could do something much simpler: Just create an ASP.NET page that processes incoming POST data in its Page_Load handler.
If your POST format is the same one used by browsers (var1=123&var2=456), you can just use Request.Form["var1"] on the page. See http://forums.asp.net/t/1464546.aspx
If your POST format is different (e.g. XML), use Request.InputStream. See http://schlueters.de/blog/archives/31-Manually-processing-HTTP-POST-data-in-an-aspx.html
You could setup a Web Method on the web server to handle the requests from the iPhone app. Then you just send the data as a normal HTTP POST and the web method would handle the data, and call the SQL Server stored procedure.
You should be able to check the Request object to see if the data was posted and then perform your call to SQL Server.
For example:
Request.Params.Get( "sampleParam" )
will return the value of a sampleParam. As long as the posting application, page, or device posted the data you are expecting you will be able to get to it.
How can I view the XML being sent to a Java Web Service from a C#-based ASP.NET page?
I've created a disco object web ref in .NET from my Java WSDL, but when I use the likes of Fiddler to view the XML attached to the HTTP request, instead I see the form parameters being passed. Is there a way I can view the serialized XML?
Use tcpmon, from Apache, which can intercept traffic and redirect it to another host/port.
You set up a listener on port A, and all traffic is forwarded to host/port B.
At a minimum, you can view at the HTTP request and response with a packet sniffer like Ethereal/Wireshark.
Or you can use the XmlSerializer and serialize the object instance you are about to pass, to the disk, for instance.
Just a thought. I am certain this is not the best way to do it, but i guess it will work. The idea is to inject a respone filter and overide the write method to log all the output generated from the ASP.NET page.
To see how to program an ASP.NET filter check this article :
http://www.highoncoding.com/Articles/468_Protecting_Email_Addresses_Using_Response_Filters.aspx