Error consuming a simple remote SOAP webservice from ASPX page - asp.net

I have a simple webservice running on a remote server that just takes a couple of strings and integers and updates a SQL Server database. I want to use it from a new ASP.NET web form.
So today I added the remote webservice to a project by adding an App_Webservice. I added the remote wsdl filename to the .NET project (in VS2005), and named the reference wsStoreData. It created a folder called wsStoreData.
The webservice has a function called StoreRecentPage. Here is the simple page code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Services;
using System.Web.UI.HtmlControls;
public partial class Training_FinalPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
wsStoreData.StoreRecentPage("1", "11", 18, 100);
}
}
The build fails with "The type or namespace name 'StoreRecentPage' does not exist in the namespace 'wsStoreData' (are you missing an assembly reference?)"
I haven't coded in .NET for a few years, so I may be missing something obvious to you. But I have looked at online examples and they don't seem to do anything different than I have done here.
Thanks for any suggestions.

You can try with this code
protected void Page_Load(object sender, EventArgs e)
{
//Idon't know name of your proxy, but it's your generated class from your Wsdl after
//adding reference
var proxy = new ProxyWebService();//Replace with your proxy class
proxy.StoreRecentPage("1", "11", 18, 100);
}

Related

Asp.net routing using Globals.asax not working properly on server.Working on local

I have the following Globals.asax.cs file.
It works perfectly on my local system.
But the following route is not working in server
http://ap6am.com/te/sdfsdf-17.html
The page is routed to http://ap6am.com/te/sdfsdf-17
Can anybody find the possible issue.
The route is working in my local sytem.But not on server.
The contents of my Globals.asax.cs is given below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;
namespace andhravilas
{
public class Global1 : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("GArticle", "Gallery/{slug}", "~/Gallery/Article.aspx");
routes.MapPageRoute("GCategory", "Gallery/Categories/{slug}", "~/Gallery/Categories.aspx");
routes.MapPageRoute("GSlideShow", "Gallery/{slug}/{id}", "~/Gallery/SlideShow.aspx");
routes.MapPageRoute("Article", "en/{slug}", "~/english/Article.aspx");
routes.MapPageRoute("enArticleHtml", "en/{slug}.html", "~/english/Article.aspx");
routes.MapPageRoute("Category", "en/Categories/{slug}", "~/english/Categories.aspx");
routes.MapPageRoute("enFeed", "en/category/english/{slug}/feed", "~/en/feed.aspx");
routes.MapPageRoute("Tags", "en/Tags/{tag}", "~/english/Tags.aspx");
routes.MapPageRoute("tArticleHtml", "te/{slug}.html", "~/telugu/Article.aspx");
routes.MapPageRoute("tArticle", "te/{slug}", "~/telugu/Article.aspx");
routes.MapPageRoute("teFeed", "te/category/telugu/{slug}/feed", "~/te/feed.aspx");
routes.MapPageRoute("tCategoryHtml", "te/Categories/{slug}.html", "~/telugu/Categories.aspx");
routes.MapPageRoute("tCategory", "te/Categories/{slug}", "~/telugu/Categories.aspx");
routes.MapPageRoute("tTagsHtml", "te/Tags/{tag}.html", "~/telugu/Tags.aspx");
routes.MapPageRoute("tTags", "te/Tags/{tag}", "~/telugu/Tags.aspx");
}
}
}
IIS pipeline process the request before MVC because ".html" are normaly a static files.
You can setup your webconfig with :
<modules runAllManagedModulesForAllRequests="true">
http://www.iis.net/learn/get-started/introduction-to-iis/iis-modules-overview#Precondition

C#/ASP.NET - Calling Web API operation via URL? : HTTP Error 500

I'm developing an ASP.NET MVC 4 application. Getting information from the database and displaying it on the webpage went well at this stage. Then I decided I'd like to develop a Web API as well side-by-side with my application's progress. So far so good, until I tried to test it using a URL on the local host.
When I tried it out, I got an HTTP Error 500.
I ran the application from VS 2010 and it opened up http://localhost:23375/ in my browser. At the end of this, I appended my API call, bringing it to:
http://localhost:23375/api/Performance/ShowMachines
When I hit enter, I get the error. Why is this so and how can I resolve it?
Here is the relevant code:
PerformanceController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using PerfMon.Models;
namespace PerfMon.Controllers
{
public class PerformanceController : ApiController
{
PerfMonDataRepository perfRep = new PerfMonDataRepository();
// GET /performance/machines
[HttpGet]
public IQueryable<Machine> ShowMachines()
{
return perfRep.GetAllMachines();
}
}
}
Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace PerfMon
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "Machines",
routeTemplate: "api/{controller}/{action}",
defaults: new {
controller = "Performance",
action = "ShowMachines"
}
);
}
}
}
I'm running into the same problem and I think I narrowed it down to the Accept header of HTTP. When you make a call to the API via JavaScript passing the Accept header as JSON or XML it works.
When you make the call from the browser, you are asking for different content types, therefore you get an error 500.
I still couldn't confirm it, but looks like that.
The issue was that when I created the .dbml file, and dragged and dropped the table into it, the automatically generated DataContext class created EntitySet objects to represent the foreign-key relationships. I created simple classes with gets sand sets to return the JSON, rather than the classes in the DataContext, excluding the EntitySet objects. As a result, it worked like a charm. Apparently EntitySets are not serializeable, and thus were giving the 500 Error.

BasicAuthentication not invoking my OnActionExecuting in Auth.cs - what may I have missed?

I have my controller decorated with: [BasicAuthentication] - however, putting in breakpoints, and stepping through the code, the [BasicAuthentication] never redirects to the Auth.cs (in the Filter folder):
Filter\Auth.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Security;
namespace ebapi.Filter
{
public class BasicAuthenticationAttribute : System.Web.Http.Filters.ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
So the override OnActionExecuting never executes - but I cannot see what I've missed. My controller, decorated with [BasicAuthentication] is shown below, but doesn't invoke my Auth.cs shown above:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using ebapi.Filter;
using ebapi.Models;
namespace ebapi.Controllers
{
public class GetBookingsController : ApiController
{
private GetBookingsContext db = new GetBookingsContext();
private ApiMembersContext dba = new ApiMembersContext();
// GET api/GetBookings/5
[BasicAuthentication]
public IEnumerable<GetBooking> GetBooking(long id)
{
Thanks for any help,
Mark
if this helps, I changed the
public class BasicAuthenticationAttribute name to: public class BasicAuthenticationV2Attribute
and changed the decoration to:
[BasicAuthenticationV2]
For whatever reason, this started the authentication again, and it fired with no problem.
I'm assuming there is some sort of caching going on, perhaps from the calling IP to the API - that means it remembers it's already authenticated someone, and doesn't need to again?
If anyone could confirm my thinking, I'd appreciate it.
Thank you,
Mark

Getting error like are you missing an assembly reference in my program

i am using this code in .net framework 3.5 , for creating a grammar using visual studio 2010 professional in win 7 but i am getting errors like
The type or namespace name 'Speech' does not exist in system (are you missing a using directive or an assembly reference.
The type or namespace name 'SpeechRecognitionType' could not be found (are you missing a using directive or an assembly reference,
similarly others like type linq does not exist are you an missing an assembly refernce.
`using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Threading;
namespace SpeechRecogTest
{
public partial class Form1 : Form
{
SpeechRecognitionEngine sr = new SpeechRecognitionEngine();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Create grammar
Choices words = new Choices();
words.Add("Hi");
words.Add("No");
words.Add("Yes");
Grammar wordsList = new Grammar(new GrammarBuilder(words));
wordsList.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecognized);
sr.LoadGrammar(wordsList);
}
void rec_SpeechRecognized(object sender, RecognitionEventArgs e)
{
MessageBox.Show(e.Result.Text);
}
}
}`
As it asks "are you missing a using directive or an assembly reference"? You're not missing the using directive, therefore it's likely you're missing the assembly. Right-click on "References" => "Add Reference" => NET tab => System.Speech dll.

How to connect an ASP.NET web application to the phone attached to the COM Port?

I am developing a application which can receive SMS messages and after reading it to send replies as SMS.
For this, I am attaching a nokia 7210 Supernova via USB to act as the GSM modem for showing demo.
This is what in my mind. But I don't know how to proceed with this. Can anyone give me good guidance??
I found a way using AT commands.
I just tested using this code snippet:
I tried to dial a number. But nothing happened in the phone.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String mobileNumber = "121312";
SerialPort sp1 = new SerialPort("COM10", 9600);
sp1.Open();
sp1.WriteLine("ATD" + mobileNumber + ";");
sp1.Close();
}
}
}
i dont think this is a good idea. there are tons of webservices which are cheaper and faster.
the other option if you want 100% control is to connect to a sms gateway of a provider via modem / isdn.

Resources