I have been searching for 4 days non stop. I am sleep deprived and going crazy. Can someone please help me or at least tell me what I'm doing wrong. This is my project
Develop a client web page app that uses the web service found at http://www.marksmerry.com/peanutbutter/WebService1.asmx.
The service generates a random number m
This service receives a guess , an integer between 1-100 inclusive. It returns a string:
low - if the guess is lower than m
equal – if the guess is correct
high - if the guess is higher than m
I have referenced the web service but I'm lost at the syntax or something please help me! This is what I have so far.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using localhost;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
localhost.WebService1 ws1 = new WebService1();
//What goes in this area. I have been searching and have tried all kinds of combination all have resulted in build errors
}
}
type ws1. and a list of methods will appear.
any service methods that were discovered by visual studio when you referenced the 'peanutbutter' webservice will be available to call on the proxy class (called WebService1 in your code example).
string result = ws1.Guess(42);
If you just type the url in the browser, it wil show you what methods it has.
http://www.marksmerry.com/peanutbutter/WebService1.asmx
I can see a web method Guess which takes an int.
As per your code, You can call it via
string result = ws1.Guess(10); // or input
When you added the reference you should have got the chance to give it a name. It's only semantics but it might be better to give it a different name from localhost.
Previous commentators have made good suggestions so I'd follow them.
Only thing I'd suggest is this.
string result = ws1.Guess("10"); //EDIT: this is wrong of course. It takes an int.
I did some work this morning using a web service.
myCoService.Service1 v24 = new myCoService.Service1();
System.Xml.XmlNode doc = v24.CreateSite(newSiteName);
Should be as simple as that.
If it isn't I'd have a look again at how you set up your web reference. Also please let us know what NET framework you are using.
I added a web Reference to a test project and a button on a page which fires this event.
protected void PeanutGuess_click(object sender, EventArgs e) {
PeanutButter.WebService1 pb = new PeanutButter.WebService1();
string response = pb.Guess(10);
lblResult.Text = string.Format("Response for 10 is " + response);
}
This works fine for me. I'm using VS2010 and the project uses Net Framework 3.5
Related
I'm dabbling in C# to write some scripts in what is otherwise a graphical machine interface programming environment (Beijer's iX Developer). The HMI is monitoring 'tags' (variables) in a PLC (programmable logic controller).
When tag Controller1_M18 turns on I want to print a report and then reset the tag. This code I'm putting in the Tags Script module is giving me error "The name 'PrintReport' does not exist in the current context". Can anyone give me guidance in fixing it?
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using Neo.ApplicationFramework.Tools.Reporting;
public partial class Report_Functions
{
void Controller1_M18_ValueOn(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
// Print the report.
PrintReport("BatchReport1");
// Reset the tag.
Globals.Tags.Controller1_M18.ResetTag();
}
}
}
The sparse scripting help file gives the information
Namespace: Neo.ApplicationFramework.Tools.Reporting
Assembly: ToolsCF (in ToolsCF.dll) Version: 2.15.5714.0
Syntax
public void PrintReport(
string reportName
)
ToolsCF.dll is present in the application folder along with all the others.
The method you are attempting to call, PrintReport simply doesn't exist in the class you have created. Either you have copy pasted this code from somewhere and missed that out or you are trying to reference a method in a different class. It's impossible to tell any more than this from the limited information provided.
Neo.ApplicationFramework.Generated.Globals.Reports.PrintReport("BatchReport1");
I have sample windows app written in C#.net and I have a global variable which i need to share to different applications when my app is running.
Below is code :
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public string GlobalValue = string.Empty;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if((textBox1.Text!="") && (textBox1.Text!=null))
{
GlobalValue = textBox1.Text.ToString();
}
}
}
}
In above code, user enters a value in text box and GlobalValue is updated on button click event.
I want to share the value of variable GlobalValue across different applications and how do i do it in C#. Suppose I'm running 3D Mark along with my sample app and this GlobalValue should be accessible to 3D Mark app or any other app.
I don't won't to use the registry to store the value.. need some other way
If an example is given, it will be really helpful for me.
thanks,
You should read this microsoft article about interprocess communication and pick the best solution for your use case.
To sum up:
File mapping is a easy way to share information (make your data looks like a file) but you need to use primitive for inter process synchronisation.
Pipe and windows sockets would help you to overcome the synchronisation issue but you'll need to have proper code in all applications needing to access (read or write) the variable.
I hope the below information will be helpful
You can use Windows Register to save any value you want.
I have this simple code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Linq;
using GadNameSpace;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GadEntities db = new GadEntities();
var images = db.Images.Where(x => x.isApproved == true).ToList();
Repeater1.DataSource = images;
Repeater1.DataBind();
}
}
Now if I'm trying to edit this line:
var images = db.Images. <--this is where intellisense is not working...
It worked before. Same file, same project, same Solution.
If I'm writing the code manually and run it, its working fine.
I tried start > cmd > "devenv /ResetSettings"
I tried to restart pc also.
The problem is with Linq intellisense only! for anything else intellisense is working fine...
Any good ideas?
Usually this happens to me when a reference to System.Data.Linq.dll is missing from the module.
I bet you have your data context in yet another assembly where the reference is set correctly (so that the code works when you compile it) but in the same time the reference is missing from the web application (and thus VS does not show the intellisense).
Sometimes, reference of EntityFramework could be missing. Please make sure that the same exists in the project you're working on.
I am using DNN6 and i creted two modules and tried to connect between them using module communicator, here is my code:
#region IntermoduleCommunication
ModuleCommunicationEventArgs oArgs = new ModuleCommunicationEventArgs();
oArgs.Value = Session["ShoppingCart"];
if (ModuleCommunication != null)
ModuleCommunication(this, oArgs);
#endregion
but i am getting 'null' in the ModuleCommunication variable?
Are you wrapping the modules in an update panel, (have the supports partial rendering option enabled) in the DNN manifest?
If I recall correctly, IMC won't work via UpdatePanels.
From whatever code you have provided, it should work. In order to get help you need to provide code for both IModuleCommunicator and IModuleListener implementation. But you can review Example implementation here. Let me know if you need more help.
Also if you are not using latest version of dnn, please try testing it by creating of latest dnn instance. Let me know if you need more help.
To get this working you need to implement the IModuleCommunicator interface. Right click on the IModuleCommunicator as showed below and extract the interface.
public partial class MyClass: PortalModuleBase, IModuleCommunicator
once extracted the following will be generated
public event ModuleCommunicationEventHandler ModuleCommunication;
I call it from a button click event
protected void btn1_Click(Object sender, EventArgs e)
{
if (ModuleCommunication == null) return;
ModuleCommunicationEventArgs args = new ModuleCommunicationEventArgs();
args.Sender = this.GetType().ToString(); ;
args.Target = "MyTarget";
}
wrap the whole thing in a try catch block to catch exceptions......hope this helps
The answer here is simple, you've forgotten exactly how events work, they are just like any other object, you have to instantiate them. aka.
public event ModuleCommunicationEventHandler ModuleCommunication = new ModuleCommunicationEventHandler(SomeStaticMethodThatWillBeCalledByDefault);
I am trying to learn and use an SDK for a vendor's product. Unfortunately, the documentation is sketchy and I've run into a void in my own knowledge of the .Net Framework.
I have some working code for a windows forms application and I am trying to get it working in an ASP.NET web form app. The vendor documentation implies you can do this but maybe you cannot..
Snippet from the working windows app:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using TRIMSDK;
private void ConnectUserBtn_Click(object sender, System.EventArgs e)
{
Database db = new Database();
Databases dbChooser = new Databases();
IDatabase dbI = dbChooser.ChooseOneUI(Handle.ToInt32());
if (dbI == null)
{
return;
}
db.Id = dbI.Id;
Now here is my attempt inside click event handler for an .ASPX page:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TRIMSDK;
protected void ConnectUserBtn_Click(object sender, EventArgs e)
{
Database db = new Database();
Databases dbChooser = new Databases();
IDatabase dbI = dbChooser.ChooseOneUI(Handle.ToInt32());
if (dbI == null)
{
return;
}
I get a compile complaint in the line just above that reads "The name 'Handle' does not exist in the current context.
This part of the SDK I am trying to use displays various modal dialogs that reflect the properties of the product to facilitate "client" development. I fear it might be only "Windows clients" and that ASP.NET web apps cannot do this.
Is there something I can add to resolve this?
For web apps, modal dialogs would be done at the client, usually via javascript and dhtml - not at the server (where ASP.NET code executes). So I fear that this product is indeed winforms only.
Just pass it:
int hwnd = 0;
IDatabase dbI = dbChooser.ChooseOneUI(hwnd);