|
I'm glad you found my response useful in some way, Philippe. If you find a better way to achieve this, I'd appreciate a message.
thanks, Bill
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
suppose my wcf has many end point with different binding.so when user / client add service ref from VS IDE at then multiple endpoint related data expose & added in client config file at client side.
Can we design service in such a way as a result only one endpoint related address will be revealed at client side?
Suppose I have one service with HTTP & TCP related endpoint and I want when external customer will add our service from their VS IDE then they will see our HTTP endpoint address not TCP. So guide me how could I do this? How to design service end config file for my requirement?
here i am attaching a small sample code for multiple endpoint related in config file.
<services>
<service behaviorConfiguration="MulContractService" name="MyWCFLibrary.MultipleContract">
<clear />
<endpoint binding="basicHttpBinding" bindingConfiguration="MulContractBasicBinding"
name="MulContractBasicEndPoint" contract="MyWCFLibrary.IMultipleContract"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IByeWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IHelloWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:8733/Design_Time_Addresses/MyWCFLibrary/MultipleContract/"
binding="netTcpBinding" bindingConfiguration="MulContractTCPBinding"
name="MulContractTCPEndPoint" contract="MyWCFLibrary.IMultipleContract" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/MyWCFLibrary/MultipleContract/" />
</baseAddresses>
</host>
</service>
</services>
tbhattacharjee
|
|
|
|
|
|
Why does your service have TCP bindings if you don't want clients of the service to consume them? Surely it would be easier to not define them at all, than to define them then hide them afterwards?
If you need different bindings for development, production etc then it would be easier to have multiple bindings defined - development bindings, production bindings etc.
In your development config you would define the bindings you require for development and testing. In your production config you define those you want for production (and therefore your external users). Your development config defines the HTTP and TCP bindings, whilst your production config only defines your production bindings.
The web.config allows you to separate the various sections to external files for just these purposes e.g. you can store all your connection strings in a separate file as follows.
<connectionStrings configSource="connectionstrings.dev.config" />
You can do the same for your bindings.
<bindings configSource="bindings.dev.config" />
<bindings configSource="bindings.production.config" />
In your development environment you would use the bindings.dev.config and in your production environment you would use the bindings.production.config (which omits the TCP bindings).
|
|
|
|
|
thanks for answer. i am new in wcf so can u please give a small full example of wcf for my situation with sample code and config code to better understand.
tbhattacharjee
|
|
|
|
|
Basically in your web.config set the configSource for the bindings section so that you specify a different file for development and live.
Your development web.config
<bindings configSource="bindings.dev.config" />
Your deployed (live) web.config
<bindings configSource="bindings.live.config" />
That's it. This is not really related to WCF, as it's more related to understanding how to construct a web.config for different environments.
|
|
|
|
|
can you please redirect me to any similar kind of article which discuss everything in details with sample code. thanks
tbhattacharjee
|
|
|
|
|
Just change your web.config file as I have suggested and you should be fine.
Where you see this....
<bindings>
change it to this....
<bindings configSource="bindings.dev.config" />
Then you need to create a new file called bindings.dev.config that holds your bindings config values for development and bindings.live.config for your live config values.
So the steps are.
1. Amend your web config file and change the binding section as described above.
2. Create two new files called bindings.dev.config and bindings.live.config
3. In your development web.config specify the bindings.dev.config
4. In your live web.config specify the bindings.live.config
|
|
|
|
|
I am be an error importing the Excel2007: "Not a legal OleAut date", you see my code below:
[CODE]
public static void ImportToSql(string excelfilepath)
{
string ssqltable = "TABHD";
string myexceldataquery = "SELECT * FROM [dbo_TABHD]";
try
{
string sexcelconnectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" + excelfilepath + "; Extended Properties=\"Excel 12.0; HDR=Yes; IMEX=2\"";
string ssqlconnectionstring = @"server = itfriend;Database=HD;integrated security = true";
//execute a query to erase any previous data from our destination table
string sclearsql = "delete " + ssqltable;
//INSERTING IT.INSTEAD I WANT TO UPDATE TABLE DATA"
SqlConnection sqlconn = new SqlConnection(ssqlconnectionstring);
OleDbConnection oledbconn = new OleDbConnection(sexcelconnectionstring);
OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
oledbconn.Open();
OleDbDataReader dr = oledbcmd.ExecuteReader();
SqlBulkCopy bulkcopy = new SqlBulkCopy(ssqlconnectionstring);
bulkcopy.DestinationTableName = ssqltable;
bulkcopy.WriteToServer(dr); // Eror in here: "Not a legal OleAut date"
Console.WriteLine(".xlsx file imported succssessfully into database.", bulkcopy.NotifyAfter);
oledbconn.Close();
}
catch (Exception ex)
{
//handle exception
MessageBox.Show(ex.Message.ToString(), "Warning !");
}
}
[/CODE]
|
|
|
|
|
|
1) i like to know what is binary Serialization and when people use binary Serialization ?
2) what is the default Serialization type?
3) how many type of Serialization exist?
4) what is basic difference between xml serialization & SOAP serialization ?
i will be happy if someone discuss all my points in details with patience. thanks
tbhattacharjee
|
|
|
|
|
You're not looking for a discussion, but answers.
1) Serialization is the process of converting an object into a stream of bits.
2) There is no default
3) There's binary, xml and soap in the framework, but more have been added by the community.
4) formatting.
MSDN - Serialization[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
|
Hi,
I have Sage Peachtree 2012. I can see the API folder in C:\Program Files (x86)\Sage\Peachtree but there are no documentation available.
Anyone tried to work on the integration to read / write into Sage Peachtree with C#?
How to get started with it?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
Googling using the following certainly seems to suggest that documentation can be found.
peachtree api documentation
|
|
|
|
|
OK, this may be a stupid question, but I am trying to write an utility method to convert an instance of a class to Dictionary<string, string> where the key being the property's name and the value being its value. I have already taken care of string and the primitive types and other types. The problem is with System.Array and collections.
What I am trying to achieve is, if I have an instance of a class having ICollection<string> MyProperty property with a few string values, the dictionary item for this property should be something like {MyProperty, {Val1,Val2,..}} i.e. comma separated values as the value for the dictionary item.
The method I have is:
private string GetValueForNonPrimitiveProperty(PropertyInfo property)
{
StringBuilder value = new StringBuilder();
if (property.PropertyType == typeof(string))
{
value.Append(property.GetValue(this));
}
else if (property.PropertyType.Namespace.Contains(CollectionsNamespace) || property.PropertyType.IsArray)
{
var collection = property.GetValue(this);
}
...
return value.ToString();
} is giving me proper value-collection in collection variable along with "appropriate" type but only at runtime (it's an object at compile-time). But since I only get to know the "actual" type of the collection (like List<string> , List<int> , etc, but List of only simple types), I am not sure how to iterate through those values.
I tried casting collection to List<object> hoping to then iterate over after casting, but the cast is returning a null .
Also, simply checking the property-type's namespace against "System.Collections" doesn't seem to be the proper way to check for a collection-type. Please suggest.
Any help would be greatly appreciated.
Whether I think I can, or think I can't, I am always bloody right!
modified 23-Sep-14 7:58am.
|
|
|
|
|
Just curious: are you actually trying handle instances of Classes that might have multi-dimensional Arrays, or generic Lists which contain other generic Lists, like: List<List<int>> ?
Is it possible you "off-load" the possibly complex parsing task by serializing the Class instance into XML, or JSON, and then read that back in, and parse that ?
Care to say why you are pursing this ?
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
No, there will only be collections of simple types (int, string, etc), as I see the classes. It's not entirely my code.
Whether I think I can, or think I can't, I am always bloody right!
|
|
|
|
|
Agent__007 wrote: there will only be collections of simple types (int, string, etc), That leaves me with the question of why this particular string format representation of the Class' content is what you want. What's wrong about the XML, or JSON result of serializing ?
In any case, good luck
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
BillWoodruff wrote: why this particular string format representation of the Class' content is what you want. As far as I am told, these values of collections (like Value1,Value2,..) will be passed to an API through its URI. I can't argue with them or even think much about it at the moment as I am working on 3 projects in parallel...
I have found a solution, please see the replies below. Thanks anyway.
And yeah, I indeed need a good luck! Thanks for that..
Whether I think I can, or think I can't, I am always bloody right!
|
|
|
|
|
I appreciate you were not offended by my question; I was planning to delete this (second) post, feeling like it kind of violates some kind of ethic I can't quite define ... "Thou shalt not Nag" ?
I post "speculative" questions on CP, and, this is the language discussion forum; may we all enjoy the freedom to explore the "outer limits," and, how excellent that, in many cases ... including this one ... the result is valuable, and educational !
cheers, Bill
« I had therefore to remove knowledge, in order to make room for belief » Immanuel Kant
|
|
|
|
|
Just out of curiosity, what is the final purpose of this exercise?
That said, you could try this code inside
else if (property.PropertyType.Namespace.Contains(CollectionsNamespace) || property.PropertyType.IsArray)
{
object[] values = (object[])property.GetValue(data, null);
if (values != null)
{
foreach (object o in values)
{
Type t = o.GetType();
}
}
}
|
|
|
|
|
Sorry, but the cast to object[] doesn't work. I have found a solution, please see Eddy Vluggen's answer below. Thanks anyway
Whether I think I can, or think I can't, I am always bloody right!
|
|
|
|
|
Hopefully this may be of some use.
List<int>; d = new List<int>() { 1, 2, 3, 4, 5, 6 };
if (typeof(IList).IsAssignableFrom(d.GetType()) == true && d.GetType().IsGenericType == true)
{
IList x = d;
Type t = x.GetType().GetGenericArguments()[0];
foreach (object item in x)
{
switch (t.Name)
{
case "Int32":
int r = (int)item;
break;
default:
break;
}
}
}
My only part I wasn't sure of was casting the object back to type that was in the list, So I used a simple switch statement to do the hard work for me. Also apologies for the crap variable naming too.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|