Calling web service from activex

D

David

Hi all,

I am having a problem trying to call my web services from an activex.

I have two webservices, one on an external web server, one on an internal
one. Basically, the client will be calling a page from the external server,
the activex will download a file and transfer it to the other webservice on
the intranet server.

We need to do it this way as the firewall rules are very strong and almost
impossible to change. However, the client is happy to allow this method, if
only I can get it to work.

Code is below...

==============================================

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using System.Drawing;

using System.IO;



// csc un.cs

// csc /t:library /out:Un.DLL un.cs



namespace GetPrePop

{

public class MyPrePop : Control

{

public static void Main(string[] m)

{

string FileName = "testfile.txt";

GetFile(FileName);

PushFile(FileName);


Form f = new Form();

MyPrePop t = new MyPrePop();

t.Dock = DockStyle.Fill;

f.Controls.Add(t);

Application.Run(f);

}



protected override void OnPaint(PaintEventArgs e)

{

e.Graphics.FillRectangle(new SolidBrush(Color.Azure), ClientRectangle);

e.Graphics.DrawLine(Pens.Blue,

new Point(ClientRectangle.Width, ClientRectangle.Height),

new Point(0, 0));

}

private static void GetFile(string FileName)

{

FetchPrePop.fetchPrePop fpp = new GetPrePop.FetchPrePop.fetchPrePop();

//fpp.GetFile(FileName);

if (!File.Exists(FileName))

{

BinaryWriter binWriter = new BinaryWriter(File.Open(FileName,
FileMode.CreateNew, FileAccess.ReadWrite));

binWriter.Write(fpp.GetFile(FileName));

binWriter.Close();

}

}

private static void PushFile(string FileName)

{

System.IO.BinaryReader br = new
System.IO.BinaryReader(System.IO.File.Open(FileName,
System.IO.FileMode.Open, System.IO.FileAccess.Read));

br.BaseStream.Position = 0;

byte[] buffer = br.ReadBytes(Convert.ToInt32(br.BaseStream.Length));

ReceivePrePop.receivePrePop rpp = new
GetPrePop.ReceivePrePop.receivePrePop();

rpp.PutFile(buffer, FileName);

br.Close();

}

}

}


==============================================

This gets compiled into a DLL and opened in the browser with...

<object id=t classid="http:GetPrePop8.DLL#GetPrePop.MyPrePop" height="300"
width="300" VIEWASTEXT>
</object>

Now, I get the picture (just a line in a bluish box), but checking my web
logs, the calls to the webservice (in GetFile and PushFile) are not
happening.

The two webservices are registered. I have tested the webservices with a
console application (running the identical code here but removing the paint
and the last 5 lines in the Main())

Are there security issues in calling webservices from within the control? Do
I need to build the control a different way?


Just for info, VS is compiling it as...
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702
/errorreport:prompt /warn:4 /define:DEBUG;TRACE
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
/debug+ /debug:full /filealign:512 /optimize- /out:blush:bj\Debug\GetPrePop8.dll
/target:library Class1.cs Properties\AssemblyInfo.cs
Properties\Settings.Designer.cs "Web References\FetchPrePop\Reference.cs"
"Web References\ReceivePrePop\Reference.cs"


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

David

Hi,

I am trying another way now...

Still having problems though.

I have created the application here...
http://www.4guysfromrolla.com/articles/052604-1.aspx

I then added a button and called this function.

private void GetFile(string FileName)

{

WebPermission myWebPermission = new WebPermission(NetworkAccess.Connect,
"http://www.mywebserver.com/");

myWebPermission.AddPermission(NetworkAccess.Connect,
"http://192.168.1.60/");

myWebPermission.Demand();

label1.Text = "getfile";

fetchPrePop.fetchPrePop fpp = new fetchPrePop.fetchPrePop();

label1.Text = "loadfpp";

receivePrePop.receivePrePop rpp = new receivePrePop.receivePrePop();

label1.Text = "loadrpp";

byte[] buffer = fpp.GetFile(FileName);

label1.Text = "collectedfile";

rpp.PutFile(buffer, FileName);

label1.Text = "pushedfile";


groupBox1.Text += " : GetFile";

}

Basically, the fpp webservice will get a file and deliver to the calling
activex control. rpp puts that file onto an intranet based webserver.

However, I am getting an error...

application attempted to perform an operation not allowed by the security
policy. To grant this application the required permission, contact your
system administrator, or use the Microsoft.NET Framework Configuration tool

This is around the System.Net.WebPermission area.

Before I added the web permission, I was getting right down to the
fpp.GetFile and then errored.

I am really stuck here. I am not sure where the WebPermission should go, or
what I should do to get it to work. Do I need to do something on my
webservers? I would find this a little odd.

Oh, I have also tried adding the two URIs into my trusted zone in internet
explorer.

From what I can see in my web logs, my first webserver is not even being
reached.

Thanks for any help.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
David said:
Hi all,

I am having a problem trying to call my web services from an activex.

I have two webservices, one on an external web server, one on an internal
one. Basically, the client will be calling a page from the external
server, the activex will download a file and transfer it to the other
webservice on the intranet server.

We need to do it this way as the firewall rules are very strong and almost
impossible to change. However, the client is happy to allow this method,
if only I can get it to work.

Code is below...

==============================================

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using System.Drawing;

using System.IO;



// csc un.cs

// csc /t:library /out:Un.DLL un.cs



namespace GetPrePop

{

public class MyPrePop : Control

{

public static void Main(string[] m)

{

string FileName = "testfile.txt";

GetFile(FileName);

PushFile(FileName);


Form f = new Form();

MyPrePop t = new MyPrePop();

t.Dock = DockStyle.Fill;

f.Controls.Add(t);

Application.Run(f);

}



protected override void OnPaint(PaintEventArgs e)

{

e.Graphics.FillRectangle(new SolidBrush(Color.Azure), ClientRectangle);

e.Graphics.DrawLine(Pens.Blue,

new Point(ClientRectangle.Width, ClientRectangle.Height),

new Point(0, 0));

}

private static void GetFile(string FileName)

{

FetchPrePop.fetchPrePop fpp = new GetPrePop.FetchPrePop.fetchPrePop();

//fpp.GetFile(FileName);

if (!File.Exists(FileName))

{

BinaryWriter binWriter = new BinaryWriter(File.Open(FileName,
FileMode.CreateNew, FileAccess.ReadWrite));

binWriter.Write(fpp.GetFile(FileName));

binWriter.Close();

}

}

private static void PushFile(string FileName)

{

System.IO.BinaryReader br = new
System.IO.BinaryReader(System.IO.File.Open(FileName,
System.IO.FileMode.Open, System.IO.FileAccess.Read));

br.BaseStream.Position = 0;

byte[] buffer = br.ReadBytes(Convert.ToInt32(br.BaseStream.Length));

ReceivePrePop.receivePrePop rpp = new
GetPrePop.ReceivePrePop.receivePrePop();

rpp.PutFile(buffer, FileName);

br.Close();

}

}

}


==============================================

This gets compiled into a DLL and opened in the browser with...

<object id=t classid="http:GetPrePop8.DLL#GetPrePop.MyPrePop" height="300"
width="300" VIEWASTEXT>
</object>

Now, I get the picture (just a line in a bluish box), but checking my web
logs, the calls to the webservice (in GetFile and PushFile) are not
happening.

The two webservices are registered. I have tested the webservices with a
console application (running the identical code here but removing the
paint and the last 5 lines in the Main())

Are there security issues in calling webservices from within the control?
Do I need to build the control a different way?


Just for info, VS is compiling it as...
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig
/nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
/debug+ /debug:full /filealign:512 /optimize-
/out:blush:bj\Debug\GetPrePop8.dll /target:library Class1.cs
Properties\AssemblyInfo.cs Properties\Settings.Designer.cs "Web
References\FetchPrePop\Reference.cs" "Web
References\ReceivePrePop\Reference.cs"


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
A

andy

Hi,

I am trying another way now...

Still having problems though.

I have created the application here...http://www.4guysfromrolla.com/articles/052604-1.aspx

I then added a button and called this function.

private void GetFile(string FileName)

{

WebPermission myWebPermission = new WebPermission(NetworkAccess.Connect,
"http://www.mywebserver.com/");

myWebPermission.AddPermission(NetworkAccess.Connect,
"http://192.168.1.60/");

myWebPermission.Demand();

label1.Text = "getfile";

fetchPrePop.fetchPrePop fpp = new fetchPrePop.fetchPrePop();

label1.Text = "loadfpp";

receivePrePop.receivePrePop rpp = new receivePrePop.receivePrePop();

label1.Text = "loadrpp";

byte[] buffer = fpp.GetFile(FileName);

label1.Text = "collectedfile";

rpp.PutFile(buffer, FileName);

label1.Text = "pushedfile";

groupBox1.Text += " : GetFile";

}

Basically, the fpp webservice will get a file and deliver to the calling
activex control. rpp puts that file onto an intranet based webserver.

However, I am getting an error...

application attempted to perform an operation not allowed by the security
policy. To grant this application the required permission, contact your
system administrator, or use the Microsoft.NET Framework Configuration tool

This is around the System.Net.WebPermission area.

Before I added the web permission, I was getting right down to the
fpp.GetFile and then errored.

I am really stuck here. I am not sure where the WebPermission should go, or
what I should do to get it to work. Do I need to do something on my
webservers? I would find this a little odd.

Oh, I have also tried adding the two URIs into my trusted zone in internet
explorer.

From what I can see in my web logs, my first webserver is not even being
reached.

Thanks for any help.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com



I am having a problem trying to call my web services from an activex.
I have two webservices, one on an external web server, one on an internal
one. Basically, the client will be calling a page from the external
server, the activex will download a file and transfer it to the other
webservice on the intranet server.
We need to do it this way as the firewall rules are very strong and almost
impossible to change. However, the client is happy to allow this method,
if only I can get it to work.
Code is below...

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
// csc un.cs
// csc /t:library /out:Un.DLL un.cs
namespace GetPrePop

public class MyPrePop : Control

public static void Main(string[] m)

string FileName = "testfile.txt";
GetFile(FileName);
PushFile(FileName);

Form f = new Form();
MyPrePop t = new MyPrePop();
t.Dock = DockStyle.Fill;



protected override void OnPaint(PaintEventArgs e)

e.Graphics.FillRectangle(new SolidBrush(Color.Azure), ClientRectangle);

new Point(ClientRectangle.Width, ClientRectangle.Height),
new Point(0, 0));

private static void GetFile(string FileName)

FetchPrePop.fetchPrePop fpp = new GetPrePop.FetchPrePop.fetchPrePop();

if (!File.Exists(FileName))

BinaryWriter binWriter = new BinaryWriter(File.Open(FileName,
FileMode.CreateNew, FileAccess.ReadWrite));




private static void PushFile(string FileName)

System.IO.BinaryReader br = new
System.IO.BinaryReader(System.IO.File.Open(FileName,
System.IO.FileMode.Open, System.IO.FileAccess.Read));
br.BaseStream.Position = 0;
byte[] buffer = br.ReadBytes(Convert.ToInt32(br.BaseStream.Length));
ReceivePrePop.receivePrePop rpp = new
GetPrePop.ReceivePrePop.receivePrePop();
rpp.PutFile(buffer, FileName);





This gets compiled into a DLL and opened in the browser with...
<object id=t classid="http:GetPrePop8.DLL#GetPrePop.MyPrePop" height="300"
width="300" VIEWASTEXT>
</object>
Now, I get the picture (just a line in a bluish box), but checking my web
logs, the calls to the webservice (in GetFile and PushFile) are not
happening.
The two webservices are registered. I have tested the webservices with a
console application (running the identical code here but removing the
paint and the last 5 lines in the Main())
Are there security issues in calling webservices from within the control?
Do I need to build the control a different way?
Just for info, VS is compiling it as...
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig
/nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing..dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseS­ervices.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.Service­s.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows..For­ms.dll
/reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
/debug+ /debug:full /filealign:512 /optimize-
/out:blush:bj\Debug\GetPrePop8.dll /target:library Class1.cs
Properties\AssemblyInfo.cs Properties\Settings.Designer.cs "Web
References\FetchPrePop\Reference.cs" "Web
References\ReceivePrePop\Reference.cs"
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com- Local franchises available- Hide quoted text -

- Show quoted text -

I think your problem is the com aspects rather than the web services.

http://dotnetslackers.com/articles/csharp/WritingAnActiveXControlInCSharp.aspx

When I tried this I could only get properties to work, not methods.
In the end I used silverlight.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top