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
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
I am creating a sample application (i.e., a proof of concept) for creating users with the Okta platform. I am using API calls but consistently receiving "BAD REQUEST" when running the C# MVC application from Visual Studio 2013 update 5 to my Okta development instance. I'm wondering if the problem is between CORS and a local app?
Here is what I have so far:
Tested out the API calls using Postman to my dev environment and the calls work (i.e., users get created in my Okta dev admin environment)
Created an API Token and call it with a prefix of "SSWS" in the Authorization header
Using an HttpClient and .PostAsJsonAsync() method to make the API call
My application code works as expected when calling a GET with the API call /api/v1/users?limit=25 and .GetAsync()
Using the following Api call: /api/v1/users?activate=false (create a user with password; this works in Postman, but not in the MVC app)
Used http://json2csharp.com/ to create C# classes that conform to Okta's JSON hierarchy (obtained from Okta's Postman API libraries)
Using the classes above, the JSON displayed in Visual Studio's Text Viewer (obtained while stepping through the code) works with a POST call when pasted into Postman
HttpResponse contains the error message "The request body was not well-formed"
Here is the code used for creating and serializing (with Json.NET) the C# classes:
RootObject root = new RootObject();
root.profile = new Profile();
root.profile.firstName = model.FirstName;
root.profile.lastName = model.LastName;
root.profile.email = model.Email;
root.profile.login = model.UserName;
root.credentials = new Credentials();
root.credentials.password = new OktaTest.Models.Password();
root.credentials.password.value = model.Password;
string rootJson = JsonConvert.SerializeObject(root);
This produces the following JSON (this contains dummy data):
{"profile":{"firstName":"Test","lastName":"User","email":"user#test.org","login":"user#test.org"},"credentials":{"password":{"value":"Testing123"}}}
Here is the line of code that makes the POST call:
HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, rootJson);
Here is the line that sets the Accept header:
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Since I'm able to use the JSON in Postman, and since that JSON comes out as valid when using JSONLint, I'm thinking that the problem is not with the JSON but something around security between my local app and the development environment. Should this test only be run from a hosted application so that a site can be explicitly assigned in the CORS section of the Okta admin environment? At this point, and I'm still researching and experimenting, I'm not sure what I'm missing, but I think I'm close.
Any advice or guidance would be greatly appreciated! Thank you!
I recommend you to use the Okta C# SDK which you can add to your application using the Okta.Core.Client NuGet package.
A sample console app shows how to use it to create Okta users: https://github.com/oktadeveloper/okta-sdk-dotnet-console-user-create
I hope this helps!
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
I am using Visual Studio 2008 and have added a web reference that points to a WCF web service.
Visual Studio has generated a client class automatically, so all I need to do to call the web service is to create an instance of the client and call the method on it.
FoodPreferenceServiceClient client = new FoodPreferenceServiceClient();
FoodPreferenceServiceResponse = client.GetFoodPreference();
The FoodPreferenceServiceClient is the web service client that is automatically generated by VS.
The GetFoodPreference is the method on the web service that I am calling.
My problem is that I want to expose the actual HTTP header received in the above call,
such as client.GetHttpResponse() or something.
Is there a way to do this?
Yes it should be possible. Try:
using (var scope = new OperationContextScope())
{
var client = new FoodPreferenceServiceClient();
response = client.GetFoodPreference();
var httpProperties = (HttpResponseMessageProperty)OperationContext.Current
.IncomingMessageProperties[HttpResponseMessageProperty.Name];
var headers = httpProperties.Headers;
// Now you should be able to work with WebHeaderCollection and find the header you need
}
you can't get the message headers through OeprationContext directly in client side, but you can develop a custom IClientMessageInspector, and in the interface you can get he SOAP XML message.
how to consume php web service in c# Desktop application. I am doing this by adding web reference and through code
WebReference.TestWSDL pdl = new testingApp.WebReference.TestWSDL();
string copy = pdl.verify("testing");
but it throws the error
Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/.
Make sure you are sending the the appropriate soap version request that the service is expecting ie sending a soap 1.2 request to a service expecting a 1.1 request would give a similar error. Maybe run fiddler and post the messages that are sent and recieved for people to have a look at?