asp.net mvc soap request - asp.net

i have URL like this : https://soapserver.example.com/blahblah.asmx?wsdl
i need to send some params to the this URL and get response.
1 - i created asp.net mvc project
2- Generated Service reference - Project > Add Service Reference > Submited URL
3 - edited controller like this
PromoKontrol.ServiceSoapClient ProKontrol = new PromoKontrol.ServiceSoapClient();
ProKontrol.PromosyonKoduKontrol(UserName, Password);
i am using breakpoint but i cant see any response?

Please make sure you assign the data returning from the service to some variable.
In the below code keep the debugging point and check the returnDate;
PromoKontrol.ServiceSoapClient ProKontrol = new PromoKontrol.ServiceSoapClient();
var returnDate = ProKontrol.PromosyonKoduKontrol(UserName, Password);

Related

How to add Bearer token to Simple OData Client

New to OData, I need to access SAP Odata Web Service that required Authentication and Token. Say I have the token hardcoded. How to add this token to Simple OData Client?
var settings = new Simple.OData.Client.ODataClientSettings();
settings.BaseUri = new Uri("https://..../UoM?$filter=wer eg '1000' &format=json");
settings.Credentials = new NetworkCredential("user1", "usrpwd");
var client = new ODataClient(settings);
Please kindly help me.
Update --
In this link : Simple Odata Client - How to add oAuth Token in each request header?
It didnot show how to add the hardcoded Token. For my problem, I need to add a given token and make a Odata Request. I check the Odata.org website, I dont seems to find any example for my case.
I have no experience on simple.Odata.client, Can some1 be kind enough to show me how.
Thanks
I believe you can use the ODataClientSettings.BeforeRequest action to alter the request before it is sent.
In the example below I set the Authorization header of the request to 'Bearer <Token>':
settings.BeforeRequest = req => {
req.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "Your_Token_Here");
};
Of course it is up to you to configure the request for you specific type of authentication.
The URL you use in your example is clearly wrong and not the OData URL for SAP.
You need the base URL for the "yourODataServiceRootURL" below and then add the relative path later in the ODataclient setting eg. "api/data/v9.1"
Instead of using the delegate method to intercept and add the Authorization header on every Http call, a clearer/cleaner solution is to instantiate the ODataClient with an HttpClient instance.
This also allows you to control the HttpClient lifecycle externally.
The code below is an extract of a .Net core app using an Azure AD OAuth2 token to connect to a Dynamics 365 OData Web API.
httpClient.BaseAddress = new Uri(yourODataServiceRootURL);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", yourBearerAccessToken);
//Use the httpClient we setup with the Bearer token header
var odataSettings = new ODataClientSettings(httpClient, new Uri("api/data/v9.1", UriKind.Relative));
var odataClient = new ODataClient(odataSettings);

Using reserved word "action" as an MVC parameter name

To provide details regarding my platform. I am using Visual Studio 2017 with a .NET Core Web project.
I am implementing a new back-end for a client for which I cannot alter the client. I am attempting to use MVC to accomplish this.
The URL which I must be able to respond to is -> https://my.server.com:8443/portal/gateway?sessionId=0A6405100000001D04FB55FE&portal=4ba457d0-e371-11e6-92ce-005056873bd0&action=cwa&token=3fcbc246bb3c35a5fa8055fec6bbf431
I would like to extract the values for :
sessionId
portal
action
token
As they all have meaning.
I have created a new view folder within my project called "Portal" and have created a new MVC controller named "PortalController".
I have created a new View called gateway.cshtml and also have implemented the following function ->
public IActionResult Gateway(string sessionId, string portal, string action, string token)
{
ViewData["Message"] = "Gateway";
return View();
}
When I set a breakpoint within the function, I receive the following values for the URL provided above ->
sessionId "0A6405100000001D04FB55FE" string
portal "4ba457d0-e371-11e6-92ce-005056873bd0" string
action "gateway" string
token "3fcbc246bb3c35a5fa8055fec6bbf431" string
As can be seen in the output of the debugger, for the parameter named "action", isntead of receiving the value "cwa" as passed by the client, I instead receive the name "gateway" which is passed by MVC as the name of the action.
Is there a "proper way" of handling this?
I would prefer to avoid altering the routes within the startup.cs file as this hurts the modularity of the code. I would welcome attributes that could be used to reroute the parameter names.
Another alternative I could see (buy can't figure out) is to simply make use of the HTTP request to read the values I'm interested in instead of using function parameters.
Thank you very much in advance for any assistance you can provide!
In .Net Core you can get your action parameter value straight off the Request with
var action= Request.Query["action"];
where in .Net Framework it was
var action= Request.QueryString["action"];

How to retrieve information from JIRA using webhooks in an ASP.Net MVC application?

I am using an MVC application that will send an email to JIRA with the information required to create an Issue in JIRA.
This is all works successfully but the next step is to retrieve the information in a page. Currently I am displaying the information that was sent by retrieving it from the database.
The problem is that I also need to retrieve the KEY and the status of the issue. This cannot be just entered as the user will not know what they are, it has to be done in JIRA.
Originally I was going to use an API to get the information from JIRA but because the JIRA site is not hosted online the API does not meet the Access-Control-Allow-Headers" Header.
I was told that I would have to use webhooks to get the information but I am unsure about how to go about this.
I know that I have to first register the webhook which I am doing Via the JIRA Administration UI. What I what to know is how can I retrieve that information in my application using webhooks, I know the webhooks must have a friendly name for the webhook created, the URL where the callback should be sent.
The scope of the webhook and the events to post to the URL, either "all events" or a specific set of events.
I also know that the Post function web hooks will not fire if added to the Create Issue workflow transition. We recommend that you configure your web hook to fire from the issue_created event instead.
So how can I successfully retrieve this information, I am currently trying this:
Public Function Webhook() As ActionResult
Dim status As String = "Status"
If Request("secret") <> status Then
Response.StatusCode = 403
Return Content("Invalid status secret")
End If
If Request("event") = "incoming_messages" Then
Dim Key As String = Request("Key")
Dim jiraStatus As String = Request("status")
Dim reply As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
reply("content") = "Thanks for your submission!"
Dim result As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
result("messages") = New Object() {reply}
Return Json(result)
Else
Response.StatusCode = 400
Return Content("Unknown event")
End If
Return View()
End Function
But I am pretty sure I am doing it wrong, what steps do I need to follow to do this correctly?
Update
Where should my Webhook URL fire to currently I am sending it to RequestB.in for testing which is working but where should I fire it to get the information in my MVC application? Should it fire to the MVC application, if so where should it fire to.
How can I process the Json payload currently in my MVC application, I am trying to deserialize it but I have not done this before and am unsure how to connect the Json Payload with the application. This is what I have tried so far:
Request.InputStream.Position = 0
Request.InputStream.Seek(0, SeekOrigin.Begin)
Using reader = New StreamReader(Request.InputStream)
Dim jiraJson = reader.ReadToEnd()
Dim contentType As String = Request.ContentType
Dim body = JsonConvert.DeserializeObject(jiraJson)
Try
Select Case DirectCast(body.key, String)
Case ""
Return Json(jiraJson)
Case Else
Return Json(jiraJson)
End Select
Catch ex As Exception
End Try
End Using
Return View()
I am unsure what to place in switch statement and also how to return the json and then display it, how can I do this?
If I'm understanding you correctly, a high level process of how this should work would be :
An email is sent to Jira.
An issue is created under the given project, which triggers the webhook.
The webhook will POST a JSON payload to the URL you've specified.
The URL should be a public route within your MVC application that consumes and processes the request.
So given where you're already at, all you need to consume the webhook is a publicly accessible MVC route. Let's say you have a controller named "JiraUpdateController", and on that controller exists a method called "ProcessWebhook" :
public class JiraUpdateController : Controller
{
/// <summary>
/// Set our default base logger for the update tasks
/// </summary>
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public static Logger Log
{
get { return logger; }
}
[HttpPost]
public ActionResult ProcessWebhook()
{
// Process the JSON payload here accordingly.
}
}
Now, you need to set this as the URL that the webhook should post to. Ultimately it should look something like :
http://internal.company.com/JiraUpdate/ProcessWebhook
I've done something very similar to this, so here's a couple things to keep in mind.
Make sure you're setting the webhook to a minimal scope. If this is something you want to trigger across all projects whenever an issue is created in any of them, you're going to have quite a few requests going to the ProcessWebhook endpoint. Try to limit the projects to just the ones you need, and the event to only the "issue created" event.
If you don't already have a public endpoint for testing, you should definitely check out RequestBin. What this will allow you to do, is setup a temporary URL for the webhook, so you can see exactly what the JSON payload from JIRA will look like. From there, build your business logic in the ProcessWebhook method, and you should be good to go. To use RequestBin, just go to the site, generate a URL, and set that as the Webhook URL. Create an issue in JIRA under the project you're working with, and you should see a large JSON payload go to that RequestBin URL - this will give you a feel for exactly what the JSON looks like and how to serialize it into a workable construct.

Calling Flipkart Api in asp.net c#

I am calling flip kart API in asp.net c# .But i got following error : 401 authorization.
I already included flip kart token and affiliate Id in Rest Header as per Prerequisites and category
URL also.So please tell me why i am getting this error. I am Calling RestApi using HttpClientRequest and my asp.net framework is 4.0
First you need to get product category link list by simple 'Get' using URL
https://affiliate-api.flipkart.net/affiliate/api/<your-affiliate-id>.<json or xml>
the response will have list of various categorizes and their url. These urls require HTTP authentication headers (your affiliate-id and access token) in the GET request. You can add like :-
WebClient wc = new WebClient();
wc.Headers.Add("Fk-Affiliate-Id", "blueskyvic");
wc.Headers.Add("Fk-Affiliate-Token", "your access code");
string res = wc.DownloadString("https://affiliate-api.flipkart.net/affiliate/feeds/blueskyvic/category/v1:6bo-ul6.json?expiresAt=1420832915393&sig=6c1167c0d141bd3edab28f9f2a980a30");//tv_video_accessories
The response will have nexturl property which will give you listing of next 50 items in that category.

Handling redirected URL within Flex app?

We have a Flex client and a server that is using the Spring/Blazeds project.
After the user logs in and is authenticated, the spring security layer sends a redirect to a new URL which is where our main application is located.
However, within the flex client, I'm currently using HTTPService for the initial request and I get the redirected page sent back to me in its entirety.
How can I just get the URL so that I can use navigatetourl to get where the app to go where it needs to?
Any help would greatly be appreciated. Thanks!
One solution would be to include a token inside a comment block on the returned page, for instance:
<!-- redirectPage="http://localhost/new-location" -->
then check for it's presence inside the HTTPService result handler. The token's value could then be used in your call to navigateToURL.
Another solution would be to examine the HTTP response headers and extract the value of the "Location" header using ActionScript. Consider using the AS3 HTTP Client lib.
From the examples page http://code.google.com/p/as3httpclientlib/wiki/Examples To determine the 'Location' header from the response:
var client:HttpClient = new HttpClient();
var uri:URI = new URI("http://localhost/j_security_check");
client.listener.onStatus = function(event:HttpStatusEvent):void {
var response:HttpResponse = event.response;
// Headers are case insensitive
var redirectLocation:String = response.header.getValue("Location");
// call navigateToURL with redirectLocation
// ...
};
// include username and password in the request
client.post(uri);
NOTE: AS3 HTTP Client depends on AS3 Core and AS3 Crypto libs.
You can also simply use the URLLoader class, no need for external code. One of the events it dispatches is HTTPStatusEvent.HTTP_RESPONSE_STATUS. Just plug into that and retrieve the redirected url:
urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, onHTTPResponseStatus);
private function onHTTPResponseStatus(event:HTTPStatusEvent):void
{
var responseURL:String = event.responseURL;
}
I am (successfully) using this code right now, so if it doesn't work for some reason, let me know.

Resources