|
I have a c++ application that needs to retrieve information from my company's server. I decided to build a c# webservice. So far it works fine. I need to add some security since I pass userid and password. But my main concern is that this webservice will only be used by our applications and I don't want it to be public to others, so that they cannot view the schema and cannot see the page that shows how to make a HTTP GET/POST and SOAP request.
Is there a way to make the webservice not available to public ? or at least hide the schema/request pages ?
|
|
|
|
|
If you're looking to add security to your web services, take a look at the Microsoft Web Service Enhancements (WSE)[^]. 2.0 was recently released. With a few simple changes to your server and clients, you can use strong authentication protocols (or a simple username/password, though I recommend at least hashing the password using MD5 or SHA1, which is easily supported by the WSE), encryption, signatures, addressing (routing), etc.
If you want it private, simply don't expose it to the public. Unless it needs to be on your Internet web server, just use it on your intranet. If you need to put it on your Internet server (say, for an extranet) then use IP address blocking (IIS feature) or features in the WSE. The latter won't prevent them from seeing the WSDL, but unless your business is about the WSDL schema and not the data that's transferred, this really shouldn't be a problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
If you're looking to add security to your web services, take a look at the Microsoft Web Service Enhancements (WSE)[^].
The client application is built under VC++ 6.0. So, for now I am using sockets to connnect and retrieve the information. I was thinking about using SSL socket. I think there are some examples on codeproject.
Heath Stewart wrote:
If you want it private, simply don't expose it to the public. Unless it needs to be on your Internet web server, just use it on your intranet
The client application is a Windows application that access the service through the Internet. It connects to our company's Web server and retrieve some data to process/display. My main concern is that service should only be available to the client applications and not to the public. If I could hide the shema returned when you point a browser to the .asmx file, that would be a good start. Then there is the ?WSDL.
It looks like there is no easy way and will have to write a .ASP page which does basically the same thing. The problem is returning the XML code, with a webservice it's all very easy.
Possible solution: Have the .ASP page call the webservice, which would not be public, and simple return the data. The .ASP would just act as a bridge between client and webservice.
|
|
|
|
|
Everything from handling requests to .asmx?WSDL to generating the WSDL itself (as well as the "human-readable" HTML output for a service) is configurable. Spend some time reading the class library documentation for the System.Web.Services and child namespaces.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Here's what I found:
Since this webservice will only be used by some client applications that already knows the schema, to hide the documentation of the web service, there is a key that can be set in the web.config file.
<br />
<?xmlversion="1.0" encoding="utf-8"?><br />
<<configuration><br />
<system.web><br />
<!--<br />
HIDE THE DOCUMENTATION FOR THE WEB SERVICE<br />
--><br />
<webServices><br />
<protocols><br />
<remove name="Documentation"/><br />
</protocols><br />
</webServices><br />
</system.web><br />
</configuration><br />
|
|
|
|
|
You can also set a custom page to be displayed for the WSDL documentation:
<?xmlversion="1.0"encoding="utf-8"?>
<configuration>
<system.web>
<!--
Custome help page\
-->
<webServices>
<wsdlHelpGeneratorhref="helpPage.aspx"/>
</webService>
</system.web>
</configuration>
It can also be a .html page. So you can display what ever you want.
A third possibility is to process the request from Application_BeginRequest function. You can check if the request has a ?wsdl to it and throw a http exception.
All these examples can be found here: http://www.15seconds.com/issue/040609.htm
|
|
|
|
|
is there any way to promote programatically a directory
(located within inetpub directory subtree) to web application?
Also I would like programatically add new IASPI mapping
(for some custom file extension to particular DLL)
for this newly created web application.
Thanks for help
Michał Januszczyk
|
|
|
|
|
You can do both programmatically using either the IIS WMI provider or the ADSI provider.
For the WMI provider, use the System.Management classes, and for the ADSI provider use the System.DirectoryServices classes.
Try the following google search for lots of examples or refine it to find exactly what you want. Documentation for the IIS WMI and ADSI providers can be found on MSDN[^].
http://www.google.com/search?q=add+virtual+directory+programmatically+to+iis[^]
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank You!
This is exactly what I needed.
|
|
|
|
|
Hi EveryBody,
I used the later code to handle some messages sent to my application
and it works, but my question is how to handle messages sent for child applications of my application(parent)
<br />
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]<br />
protected override void WndProc(ref Message m)<br />
{<br />
switch (m.Msg)<br />
{<br />
<br />
case WM_SIZING:<br />
MessageBox.Show("Sizing");<br />
return ;<br />
case WM_SIZE:<br />
MessageBox.Show("Size");<br />
if(m.WParam==(IntPtr)SIZE_MINIMIZED)<br />
MessageBox.Show("SIZE_MINIMIZED");<br />
else if(m.WParam==(IntPtr)SIZE_MAXIMIZED)<br />
MessageBox.Show("SIZE_MAXIMIZED");<br />
return;<br />
<br />
case SW_MAXIMIZE:<br />
MessageBox.Show("SW_MAXIMIZE");<br />
return;<br />
<br />
case WM_MOVING:<br />
MessageBox.Show("Moving");<br />
return;<br />
}<br />
base.WndProc(ref m);<br />
}<br />
<br />
Please I need a very fast help.
Thank you .
|
|
|
|
|
Child applications? There's no such thing. Are you talking about child Windows or MDIChildren? Each form has it's own message pump. Your parent form will not get the messages meant for child forms.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave's right about the message pump. Some controls will send their parents messages, and these are documented in the Platform SDK (almost every control in Windows Forms encapsulates Windows Common Controls).
There is another way, though. Implement the IMessageFilter interface and add an instance of your implementation using Application.AddMessageFilter . This installs a message filter for the application's message pump, which will trap messages and allow you to process them (or even remove them) before dispatching them to their destination windows.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can serialize my class with xmlserializer.
but when i add a DataTable typed property to my class, xmlserializer submit an error to me.
please guide to me.
|
|
|
|
|
We need the error mesage you're getting. We also need to know how your adding this DataTable to your class. Some code snippets would help alot.
Without these items, it's impossible to tell you what your doing wrong.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Collections;
using System.Data ;
/* The XmlRootAttribute allows you to set an alternate name
(PurchaseOrder) of the XML element, the element namespace; by
default, the XmlSerializer uses the class name. The attribute
also allows you to set the XML namespace for the element. Lastly,
the attribute sets the IsNullable property, which specifies whether
the xsi:null attribute appears if the class instance is set to
a null reference. */
[XmlRootAttribute("PurchaseOrder", Namespace="http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
public string OrderDate;
/* The XmlArrayAttribute changes the XML element name
from the default of "OrderedItems" to "Items". */
[XmlArrayAttribute("Items")]
public OrderedItem[] OrderedItems;
public decimal SubTotal;
public decimal ShipCost;
public decimal TotalCost;
}
public class Address
{
/* The XmlAttribute instructs the XmlSerializer to serialize the Name
field as an XML attribute instead of an XML element (the default
behavior). */
[XmlAttribute]
public string Name;
public string Line1;
/* Setting the IsNullable property to false instructs the
XmlSerializer that the XML attribute will not appear if
the City field is set to a null reference. */
[XmlElementAttribute(IsNullable = false)]
public string City;
public string State;
public string Zip;
}
public class OrderedItem
{
public string ItemName;
public string Description;
public decimal UnitPrice;
public int Quantity;
public decimal LineTotal;
/* Calculate is a custom method that calculates the price per item,
and stores the value in a field. */
public void Calculate()
{
LineTotal = UnitPrice * Quantity;
}
}
public class Test
{
public static void Main()
{
// Read and write purchase orders.
Test t = new Test();
t.CreatePO("po.xml");
t.ReadPO("po.xml");
t.CreatCol() ;
}
private void CreatCol()
{
XmlSerializer serializer =
new XmlSerializer(typeof(MyCoulumnClollectionClass));
TextWriter writer = new StreamWriter("Hadi.xml");
MyCoulumnClollectionClass d=new MyCoulumnClollectionClass() ;
SCol s1=new SCol() ;
s1.FieldName ="stud_no" ;
s1.DisplayName="stud_displayname";
d.Add(s1);
s1=new SCol() ;
s1.FieldName="FN2" ;
s1.DisplayName="DN2" ;
s1.AAAA="====" ;
d.Add(s1) ;
serializer.Serialize(writer, d);
writer.Close();
}
private void CreatePO(string filename)
{
// Create an instance of the XmlSerializer class;
// specify the type of object to serialize.
XmlSerializer serializer =
new XmlSerializer(typeof(PurchaseOrder));
TextWriter writer = new StreamWriter(filename);
PurchaseOrder po=new PurchaseOrder();
// Create an address to ship and bill to.
Address billAddress = new Address();
billAddress.Name = "Teresa Atkinson";
billAddress.Line1 = "1 Main St.";
billAddress.City = "AnyTown";
billAddress.State = "WA";
billAddress.Zip = "00000";
// Set ShipTo and BillTo to the same addressee.
po.ShipTo = billAddress;
po.OrderDate = System.DateTime.Now.ToLongDateString();
// Create an OrderedItem object.
OrderedItem i1 = new OrderedItem();
i1.ItemName = "Widget S";
i1.Description = "Small widget";
i1.UnitPrice = (decimal) 5.23;
i1.Quantity = 3;
i1.Calculate();
// Insert the item into the array.
OrderedItem [] items = {i1};
po.OrderedItems = items;
// Calculate the total cost.
decimal subTotal = new decimal();
foreach(OrderedItem oi in items)
{
subTotal += oi.LineTotal;
}
po.SubTotal = subTotal;
po.ShipCost = (decimal) 12.51;
po.TotalCost = po.SubTotal + po.ShipCost;
// Serialize the purchase order, and close the TextWriter.
serializer.Serialize(writer, po);
writer.Close();
}
protected void ReadPO(string filename)
{
// Create an instance of the XmlSerializer class;
// specify the type of object to be deserialized.
XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrder));
/* If the XML document has been altered with unknown
nodes or attributes, handle them with the
UnknownNode and UnknownAttribute events.*/
serializer.UnknownNode+= new
XmlNodeEventHandler(serializer_UnknownNode);
serializer.UnknownAttribute+= new
XmlAttributeEventHandler(serializer_UnknownAttribute);
// A FileStream is needed to read the XML document.
FileStream fs = new FileStream(filename, FileMode.Open);
// Declare an object variable of the type to be deserialized.
PurchaseOrder po;
/* Use the Deserialize method to restore the object's state with
data from the XML document. */
po = (PurchaseOrder) serializer.Deserialize(fs);
// Read the order date.
Console.WriteLine ("OrderDate: " + po.OrderDate);
// Read the shipping address.
Address shipTo = po.ShipTo;
ReadAddress(shipTo, "Ship To:");
// Read the list of ordered items.
OrderedItem [] items = po.OrderedItems;
Console.WriteLine("Items to be shipped:");
foreach(OrderedItem oi in items)
{
Console.WriteLine("\t"+
oi.ItemName + "\t" +
oi.Description + "\t" +
oi.UnitPrice + "\t" +
oi.Quantity + "\t" +
oi.LineTotal);
}
// Read the subtotal, shipping cost, and total cost.
Console.WriteLine("\t\t\t\t\t Subtotal\t" + po.SubTotal);
Console.WriteLine("\t\t\t\t\t Shipping\t" + po.ShipCost);
Console.WriteLine("\t\t\t\t\t Total\t\t" + po.TotalCost);
}
protected void ReadAddress(Address a, string label)
{
// Read the fields of the Address object.
Console.WriteLine(label);
Console.WriteLine("\t"+ a.Name );
Console.WriteLine("\t" + a.Line1);
Console.WriteLine("\t" + a.City);
Console.WriteLine("\t" + a.State);
Console.WriteLine("\t" + a.Zip );
Console.WriteLine();
}
protected void serializer_UnknownNode
(object sender, XmlNodeEventArgs e)
{
Console.WriteLine("Unknown Node:" + e.Name + "\t" + e.Text);
}
protected void serializer_UnknownAttribute
(object sender, XmlAttributeEventArgs e)
{
System.Xml.XmlAttribute attr = e.Attr;
Console.WriteLine("Unknown attribute " +
attr.Name + "='" + attr.Value + "'");
}
}
public class SCol
{
// public string FiledName
// {
// get
// {
// return m_fieldName ;
// }
// }
// public void SetFiledName(string f)
// {
// m_fieldName=f ;
// }
[XmlElement(ElementName = "TaxRate")]
public string FieldName
{
get
{
return m_ ;
}
set
{
m_=value ;
}
}
public string DisplayName ;
// ***** in this property , xmlSerializer submit error ***
public DataTable m_columnTable ;
private string m_ ;
[XmlElement]
public string AAAA ;
}
public class MyCoulumnClollectionClass : CollectionBase
{
//[XmlElement(ElementName = "Collection")]
//[XmlArrayAttribute("Items")]
public SCol this[ int index ]
{
get
{
return( (SCol) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( SCol value )
{
return( List.Add( value ) );
}
public int IndexOf( SCol value )
{
return( List.IndexOf( value ) );
}
public void Insert( int index, SCol value )
{
List.Insert( index, value );
}
public void Remove( SCol value )
{
List.Remove( value );
}
public bool Contains( SCol value )
{
// If value is not of type Int16, this will return false.
return( List.Contains( value ) );
}
}
|
|
|
|
|
I creat a component that have a collection object.
when i use this component on my form, and fill collection and save form, the collection`s contetnt not save into form`s resource.
please guide to me.
|
|
|
|
|
If by "form's resource" you mean the ResX file, then you have to use a CodeDomSerializer derivative that uses the System.Resources namespace classes.
If you want to simple serialize the collection to code in your .cs source file, then just use the DesignerSerializationVisibilityAttribute :
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyCollection MyObjects
{
} That's it.
If you want custom serialization, again extend CodeDomSerializer . If all you want is to serialize a collection like a ComboBox would for items, for example, then just use the attribute and enumeration value I mentioned above.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello.
Thank you very much for your guiding. it is very interest.
I use "[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]" in a collection that contain "int" data type and it is ok. But when i use this attribute for a collection that contain a class or struct , it is not work , mean that the contect of content class of collection not save in form code.
please guide to me again, very very thank you.
Hadi: hd_ali@yahoo.com
|
|
|
|
|
Hi!
I’ve read about a topic like this earlier. I would like a program to generate a picture of my programming project from my .sc (C#) or my .h (C++) files.
Anyone got a tip of a good free alternative? I’m using VS.NET and would be very happy if I have a solution there…
I’ve heard about MS Visio but is there a possibility to load existing files in the way I want?
...and justice for all
APe
|
|
|
|
|
Microsoft Visio Professional adds a plugin for VS.NET that will generate a UML diagram for your project.
Rational XDE (got $2,500 bucks to spare?) allows you to do this from within VS.NET and synchronize your class diagram with your project.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Actualy i have Microsoft Visio Professional.
Where do i find and use the plugin in VS.NET?
Thanks
...and justice for all
APe
|
|
|
|
|
It was an install option when you installed Visio. It's only available for VS.NET 2003, IIRC. It should've installed by default. Just click on Project menu and you should see a Visio UML menu item.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Please HELP.
I have class hierarchy model (a.k.a. an Object Domain), where I store my data. This objects are finaly stored in ArrayList that I use as DataSource for my DataGrid.
This idea corectly works with fixed columns count, because objects in ArrayList have property for each column and DataGrid maps this properties.
How can I customize my model for variable columns count?
I try to change my structured objects to collections and properties to array property. However, in this case, DataGrid can't map this property and columns can't be append.
Any help is much appreciated.
Sincerely,
Morfo
|
|
|
|
|
What is the use of following method?
Graphics.AddMetafileComment(metaComment);
where do and what for we use MetaFile Comments?
Please guide
reagrds
|
|
|
|
|