Communication between a Client -> WCF Service -> ASP.NET Webpage - c#

i try to build a Client which sends data to a WCF Service. There is an ASP.NET Webpage which should recieve those information and put them in textfields etc.
Here is the method in my client:
OutlookPluginService.BookingRequest breq = new OutlookClient.OutlookPluginService.BookingRequest();
breq.subject = "This is my subject";
breq.numParticipants = 6;
client.getBookingURL("1234", breq);
This method sends the data to the WCF Webservice and recieves the ASP.NET URL.
This is my WCF Method:
public string getBookingURL(string guid, BookingRequest request,string token,string exitURL)
{
BookingRequest breq = new BookingRequest();
HttpContext current = HttpContext.Current;
string baseUrl = current.Request.Url.Scheme + "://"
+ current.Request.Url.Authority
+ current.Request.ApplicationPath.TrimEnd('/') + '/'
+ "WebPage/Booking/BBooking.aspx";
return baseUrl;
}
i can access to the data from here but i dont know how to transfer the data to the asp.net Webpage.
is it possible to solve this problem with sessions?
thanks in advance for your help/ideas

you have two options;
1) you may use pooling, which makes calls to the related service in predetermined time intervals to fetch the newly added data.
or
2) you may use a pull - push structure which enables you to push data from your WCF service to your ASP.NET application. Refer to How do I implement a Push-Pull web application in C# asp.net

Related

SOAP error when connecting to NetSuite web services: "Namespace prefix ' soapenv' not defined"

I am getting the following error when connecting to a NetSuite production account, through the Suitetalk API:
I don't have problems connecting to the Sandbox account for this client. I am connecting through a C# WCF project. I don't believe the problem is with the c# project, since this code is being used in Production with many other clients.
It seems to me like the SOAP message being returned is incorrectly formatted - there seems to be a line break before the 'soapenv' element in the SOAP message. I am getting this error when creating a "get" request against the API(using passport login). This error occurs on any API call though, I did try simply logging in through the API as well.
I have double checked the login details and account information for this client and everything seems in orders. Besides, if this information is incorrect, I should be getting authentication errors - not malformed SOAP messages.
Any help will be appreciated, thanks!
It turns out that I needed to use the webservices.na3.netsuite WSDL. I was under the impression that the regular "webservices.netsuite" WSDL would direct any requests to the correct server.
So when connecting to a NetSuite account through SuiteTalk, be sure to make use of the correct WSDL and specify the correct endpoint along with your login credentials. You can check which server your account is hosted on by looking at the URL when logged into your NetSuite account.
Update
I made use of the newest 'DataCenterAwareNetSuiteService' class to dynamically get the correct data center for the current account that I am trying to connect to:
class DataCenterAwareNetSuiteService : NetSuiteService
{
private System.Uri OriginalUri;
public DataCenterAwareNetSuiteService(string account, bool doNotSetUrl)
: base()
{
OriginalUri = new System.Uri(this.Url);
if (account == null || account.Length == 0)
account = "empty";
if (!doNotSetUrl)
{
//var temp = getDataCenterUrls(account);
DataCenterUrls urls = getDataCenterUrls(account).dataCenterUrls;
Uri dataCenterUri = new Uri(urls.webservicesDomain + OriginalUri.PathAndQuery);
this.Url = dataCenterUri.ToString();
}
}
public void SetAccount(string account)
{
if (account == null || account.Length == 0)
account = "empty";
this.Url = OriginalUri.AbsoluteUri;
DataCenterUrls urls = getDataCenterUrls(account).dataCenterUrls;
Uri dataCenterUri = new Uri(urls.webservicesDomain + OriginalUri.PathAndQuery);
this.Url = dataCenterUri.ToString();
}
}
The above is called like so:
new DataCenterAwareNetSuiteService("*account number*", false);
With the latest version of NetSuite, some changes have been made to URLs. For instance, now you can have more than one SandBox URL. Because of this, the URL format has changed. The account number used when authenticating is also now different. For sandboxes the account Id is now passed up as ACCOUNTNUMBER_SANDBOXID, for example 12345678_SB1.
You can determine the URLs for the SOAP and REST services by using the datacenterurls endpoint and supplying the account # you would like to determine the URLS for.
https://rest.netsuite.com/rest/datacenterurls?account=YOUR_ACCOUNT_NUMBER
The functionality below is based on the answer from #Charl above.
I have made a couple changes below that provides the same functionality without using inheritance.
This may be a simpler implementation for a newer programmer who does not know how to use an inherited class.
var accountId = "1234567"; // Insert your account ID here
var Service = new NetSuiteService();
Service.Url = new Uri(Service.getDataCenterUrls(accountId).dataCenterUrls.webservicesDomain + new Uri(Service.Url).PathAndQuery).ToString();

How to authenticate SharePoint Rest API calls from c# back end? (Read details)

I am trying simple application which listens for http requests and makes rest api calls to Sharepoint 2013.
Scenario:
A user makes a get request from the browser to the back-end (which is in c#). The sharepoint api is called from back-end. Now it should use the logged in users credentials for this request but I get unauthorized error.
Calling rest api directly from browser works.
Note :
Users are authenticated with AD so I don't want to request credentials again in my app.
Most solutions that I find assume that user is logged in on the machine making rest calls (back-end) but its different scenario.
Security header is mandatory to call SharePoint API. You have different ways to get the AccessToken, including pure HTTP calls to ADFS or login.microsoft, but I do think you need it.
A sample using native Client Context.
ClientContext clientContext = new ClientContext(someSharePointUrl);
clientContext.ExecutingWebRequest += delegate (object sender, WebRequestEventArgs e)
{
e.WebRequestExecutor.WebRequest.Headers["Authorization"] = string.Format("Bearer {0}", someUserToken);
};
//... then use clientContext as usual
A sample using more usual REST call, also including formDigest
HttpWebRequest itemRequest =
(HttpWebRequest)HttpWebRequest.Create(hostUrl + "/_api/Web/lists/getbytitle('" + listName + "')/items");
itemRequest.Method = "POST";
itemRequest.ContentLength = itemPostBody.Length;
itemRequest.ContentType = "application/json;odata=verbose";
itemRequest.Accept = "application/json;odata=verbose";
itemRequest.Headers.Add("Authorization", "Bearer " + token);
itemRequest.Headers.Add("X-RequestDigest", formDigest);
Other option is to use AppOnlyToken, but you then have impersonate calls to API and need to manage User ID yourself !

Magento Change Order Status from REST API

I am 'communicating' with a Magento web app(version 1.9.2.2) via the REST API in a C# ASP.NET MVC application.
The application essentially acts as a backend order flow dashboard for pizzas. I need to display the latest orders and allow the user to check the items off as they are processed (among other things).
I am able to retrieve orders, products, customers etc; but need to be able to update the order status. From my research it seems that this can be achieved by adding an order comment.
That said, my questions are as follows:
Is adding an order comment (thus updating the order status) only possible through the SOAP Service in Magento 1.9?
If the above is true, how can I update the order status of a particular order using another secure approach?
Docs on REST API: http://devdocs.magento.com/guides/m1x/api/rest/Resources/Orders/order_comments.html
To anyone that may be facing the same issue, I discovered that it is not possible to update the order status (AKA add a sales order comment) via the REST API. You have to use the SOAP API and version 2 makes it easiest.
Setup:
In magento, create a SOAP Role and User
Add the SOAP v2 API as a web reference to your Visual Studio project
Code:
public void UpdateOrderStatus(string orderIncrementId, string newStatus, string comment = "")
{
// Init service with uri
var service = new MagentoSoap.MagentoService();
// Login - username and password (soap api key) of the soap user
string sessionId = service.login(Username, Password);
// Update order status
service.salesOrderAddComment(sessionId, orderIncrementId, newStatus, comment, 1, true);
}
You can do this by using the addComment method, which also lets you specify the new order status as one of it's parameters.
$sku='100000003';
$orderStatus = 'Downloaded';
$comment = 'The order was successfully downloaded';
$sendEmailToCustomer = false;
$proxy->call($sessionId, 'sales_order.addComment', array($sku, $orderStatus, $comment, $sendEmailToCustomer));

Is it possible to take asp.net web adress from IIS

I want to read web services information especially adress from iis.
For IIS7 I can read following information with this code.
var iisManager = new ServerManager();
sites = iisManager.Sites;
foreach (var site in sites)
{
IISService serv = new IISService();
serv.Name = site.Name;
serv.State= site.State.ToString();
serv.PhysicalPath= site.Applications["/"].VirtualDirectories[0].PhysicalPath;
allServices.Add(serv);
}
For II6
DirectoryEntry IIsEntities = new DirectoryEntry(Path);
foreach (DirectoryEntry IIsEntity in IIsEntities.Children)
{
if (IIsEntity.SchemaClassName == "IIsWebServer")
{
yield return new Website
(
IIsEntity.Properties["ServerComment"].Value.ToString(),
GetPath(IIsEntity),
(ServerState)IIsEntity.Properties["ServerState"].Value
);
}
}
I can read above information but I want to read end point information of asmx web service.
Thats like :
http://localhost:8091/Service1.asmx
Is it possible read port number or name of asmx file ?
Nope. IIS has nothing to do with it. IIS only concerns about hosting-related operations and serving requests. If you are talking about services, you might want to look at making your services discoverable, exposing metadata and WSDL. However, this will not expose any file or any "internals" of the service...just the interface (public facing details)...for example if you have a RESTful service, the physical files behind it will not be exposed.
I ask IIS for local adresses so I can succeded to get enough information to form asmx local web adress.
foreach (var site in sites)
{
IISService serv = new IISService();
serv.Name = site.Name;
serv.State= site.State.ToString();
serv.PhysicalPath= site.Applications["/"].VirtualDirectories[0].PhysicalPath;
System.Net.IPEndPoint endP = site.Bindings[0].EndPoint;
string protocol = site.Bindings[0].Protocol;
allServices.Add(serv);
}
I can get Binding information with this solution(port and Protocol). I
can find Service1.asmx file when I ask for *.asmx with Directory.GetFiles in PhysicalPath. So I get needed information to construct web services adress.
//What I need http://localhost:8091/Service1.asmx
string adress = protocol + "://localhost:" + endP.Port + "/" + " *.asmx file from PhysicalPath";

How do I create a webhook in ASP.NET MVC?

I'm trying to create a simple webhook to receive a delivery receipt from Nexmo SMS service. The only documentation on their website was this.
During account set-up, you will be asked to supply Nexmo a CallBack URL for Delivery Receipt to which we will send a delivery receipt for each of your SMS submissions. This will confirm whether your message reached the recipient's handset. The request parameters are sent via a GET (default) to your Callback URL and Nexmo will be expecting response 200 OK response, or it will keep retrying until the Delivery Receipt expires (up to 72 hours).
I've been searching for ways to do this, and so far I have this method from an example I found online, although I'm not sure if this is correct. Anyways, this is being run on ASP.NET and on port 6563, so is this the port I'm supposed to be listening to? I downloaded an application called ngrok which should expose my local web server to the internet, so I ran the application and instructed it to listen onto port 6563, but no luck. I've been fiddling with it trying to find someway to post to this function.
[HttpPost]
public ActionResult CallbackURL()
{
System.IO.StreamReader reader = new System.IO.StreamReader(HttpContext.Request.InputStream);
string rawSendGridJSON = reader.ReadToEnd();
return new HttpStatusCodeResult(200);
}
Usually I can call the function directly to return the view just by visiting http://localhost:6563/Home/Index/CallbackURL
So I've inserted a breakpoint on the method signature, but it'll only get called if I remove the [HttpPost] from it. Any next steps that I should try?
First you have to remove the [HttpPost] bit because it clearly states that "parameters are sent via a GET".
Then you should also remove the return HttpStatusCodeResult(200) as it will return the 200 OK status code anyway if no error occures.
Then you should simply read the values from querystring or using model binding. Here is a sample:
public string CallbackURL()
{
string vals = "";
// get all the sent data
foreach (String key in Request.QueryString.AllKeys)
vals += key + ": " + Request.QueryString[key] + Environment.NewLine;
// send all received data to email or use other logging mechanism
// make sure you have the host correctly setup in web.config
SmtpClient smptClient = new SmtpClient();
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("...#...com");
mailMessage.From = new MailAddress("..#....com");
mailMessage.Subject = "callback received";
mailMessage.Body = "Received data: " + Environment.NewLine + vals;
mailMessage.IsBodyHtml = false;
smptClient.Send(mailMessage);
// TODO: process data (save to database?)
// disaplay the data (for degugging purposes only - to be removed)
return vals.Replace(Environment.NewLine, "<br />");
}
Before couple of weeks Asp.Net team has announced to support Web Hooks with Visual Studio.
Please have a look here for more detailed information:
https://neelbhatt40.wordpress.com/2015/10/14/webhooks-in-asp-net-a-visual-studio-extension/
Microsoft is working on ASP.NET WebHooks, a new addition to the ASP.NET family. It supports a lightweight HTTP pattern providing a simple pub/sub model for wiring together Web APIs and SaaS services.
See Introducing Microsoft ASP.NET WebHooks Preview
So the issue I was having wasn't with my webhook at all, it was actually with IIS Express. Apparently it blocks most traffic from foreign hosts so there is some tweaking you can do before tunneling anything to your server. If you follow these guides you should have a working server.
https://gist.github.com/nsbingham/9548754
https://www.twilio.com/blog/2014/03/configure-windows-for-local-webhook-testing-using-ngrok.html

Categories