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
Related
When I run my Html code it only display JSON result but if I use console to call the http it display the whole code of the web form. What can I change to make it only display the JSON result on console app?
[Html Code]
[console result]
using (var client = new WebClient()) //WebClient
{
client.Encoding = System.Text.Encoding.UTF8;
client.Headers.Add("Content-Type:application/json");
client.Headers.Add("Accept:application/json");
var result = client.DownloadString("http://localhost:49299/test.aspx");
Console.WriteLine(result);
Console.ReadLine();
}
You are reading the whole web page response, which includes all the HTML and the JavaScript.
Apparently, what you want is the result of a JavaScript function that is being run on the page by the browser. They way I would solve that is by letting the JavaScript do a XHR call back to the server containing the result.
Since you are using ASP.NET you could set up a ASP.NET Web API project to respond to such REST calls.
Your server code just only return html that contain javascript. If you request to the server by a web browser, the browser will execute javascript and you see the right data. Meanwhile, if you make requests by C# code, javascript will not be executed. So you need to know
How asp.net webforms return json data here How to return a JSON object in standard web forms .Net
How to consume google geocoder api by C#. You can manually request to google api by C# or just utilize a wrapper. May be this https://github.com/chadly/Geocoding.net. I have not yet tried this before
My website is Asp.net mvc and I want to use one Company post my Product
their web is php and web service is php in document is clear how use php but I want call php functions and get response on my asp website how can I send request
<?PHP
$soap = new SoapClient("http://www.froservice.ir/F-W-S-L/F_Gateway.php?wsdl");
$ResNum = $_REQUEST['ResNum'];
$RefNum = $_REQUEST['RefNum'];
$State = $_REQUEST['State'];
$VerifyUrl = "http://www.YourSite/verify.php";
$Res = $soap->FVerifyEndbuy($ResNum,$RefNum,$State,$VerifyUrl,$Username,$Password);
$Res=urldecode($Res);
echo $Res;
?>
how call this function?
You can try adding a service reference to your MVC project. Right-click References, Add Service Reference, use the soap client URL. You will then have a class that you can call methods on like any other class. But I wouldn't guarantee that service is completely interoperable with ASP.NET service references. If it doesn't work, you can always build a request and parse the response manually with HttpClient
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.
I am new to web service. I want to send the XML file to the web method without adding reference to webservice class, using Post method but every time i am getting Error 500
can any body help me?????
If you're using ASMX (.Net 2.0) services then you can change the webservice URL at runtime.
I don't find any other reason for not adding a Web service reference.
Also for 500 Internal Server Error check whether you can access the web service.
This should solve your issue.
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