|
Thanks for review and confirmation, jkersch!
I am new to this topic.
regards,
George
|
|
|
|
|
Hello everyone,
For the namespace defined for WCF, e.g.
http://msdn.microsoft.com/en-us/library/ms731835.aspx
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
my question is, what is it usage for developer? The only usage I found is used by the proxy class generated by meta data, and transparent to developer. When do we need to deal with namespace?
thanks in advance,
George
|
|
|
|
|
well, at least in my company, we use namespaces e.g. for versioning.
for example:
[ServiceContract(Namespace = "http://www.mycompany.com/product/2007/12")]
and
[ServiceContract(Namespace = "http://www.mycompany.com/product/2008/08")]
notice the difference? at least for us this eases versioning.
but i guess this is just one reason for using namespaces
|
|
|
|
|
Thanks jkersch,
But even if they are of different namespaces, the client of WCF does not need namespace information to access, just need endpoint address, correct? My question is, does the client of WCF needs to use the namespace?
regards,
George
|
|
|
|
|
hi george,
well...i guess this depends on your scenario. if you just want to simply consume a webservice, you probably won't need adding namespaces to your servicecontracts.
but if things get larger, complexer, ... i guess it's doesn't harm starting to add namespaces to you services, but as i said, if you're in a simple scenario, your clients probably don't care about namespaces at all.
regards
j.
|
|
|
|
|
Thanks jkersch,
I agree with your comments. But from WCF client point of view, there is no need to provide namespace information of the service, only endpoint information is fine. Agree?
So, my confusion is how could WCF client use namespace?
regards,
George
|
|
|
|
|
well, if you ask how you could retrieve the service namespace from withing the client, thats not very complicated. your service proxy has an Endpoint property that contains information about the service endpoint. there you can find a contract-property that contains (with some other information) the namespace.
it's up to you wheter you can use the service namespace in the client, but i guess in most cases where you just simply want to communicate with a service, do some stuff and disconnect after it, you don't have to bother with namespace on the client side.
But at least there is the possibility to use it (like most of the stuff in WCF, hardly anyone will ever use ALL of its features
regards
j.
|
|
|
|
|
Thanks jkersch,
1.
My question is, I have read through here,
http://msdn.microsoft.com/en-us/library/ms733133.aspx[^]
but it does not contain any description about how to use namespace information of the remote WCF service, do you have any samples or documents to refer to me about how to utilize namespace from client side?
2.
How namespace information is used at server side?
regards,
George
|
|
|
|
|
Hi,
How can set focus to one particular row in the DataGridView?
(I want to trigger a event like button_click or whatever)
What is the propriety for that?
nelsonpaixao@yahoo.com.br
|
|
|
|
|
Hi nelsonpaixao,
You may try this - YourDataGridView.Rows[rowindex].Selected = true .
Hope this help.
regards
cocoonwls
|
|
|
|
|
thanks i will chect that
nelsonpaixao@yahoo.com.br
|
|
|
|
|
Tonight I came accross an issue when using a Find method on a collection where I needed to idealy null test an item in the collection. The problem was the collection was a List of struct - and structs can't be null!
I got round it by testing a property in the struct (which was a class so null was possible).
I 'googled' and found this[^] interesting solution. Just wondered what the experts here thought about it?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
A couple of thoughts. If null is a valid state for an element of the collection, then shouldn't the collection be declared for example:
struct myStruct { ... }
List<myStruct?> list;
Alternatively you could define an empty state for myStruct and compare against that, in the same way that Point or Size work, for instance.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
It would be much easier to make it nullable.
In C# 2.0 onwards, to create a nullable struct declare it like this:
int? myNullableInt = null;
Note the question mark after the type name. This indicates that it is actually a nullable int, and as you can see you can assign null to it.
So, to declare a list of nullable struct types, try something like this:
List<int?> myNullableIntList = new List<int?>;
|
|
|
|
|
That causes problems when trying to access properties of the struct but I get the idea!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
If you're trying to keep the check simple and elegant, you could try an approach of returning either the nullable item, or when null a default item, something similar to:
struct myStruct {
public bool IsValid;
public readonly myStruct Empty;
}
foreach(myStruct? item in collection) {
if((item ?? myStruct.Empty).IsValid) {
...
}
}
The ?? operator returns whats on the left if not null or else whats on the right.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
It works when definining an object that way but not when derriving from List<struct>
See below[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
I'll second Colin's suggestion (use the Nullable type). I just thought I'd explain how it works, essentially the nullable operator (? ) in C# is syntatic sugar like LINQ which tells the compiler to change:
int? myInt;
Nullable<int> myInt; Nullable is a class defined in the System namespace and has two properties, Value and HasValue (almost exactly what you're suggesting implementing), however the operators are already implemented so for most cases you can forget you're dealing with a nullable type (just remember to perform null checks).
|
|
|
|
|
I think I get it - but how to make it work?
Consider this simple sample code:
public struct X
{
private string m_Property;
public string Property
{
get { return m_Property; }
set { m_Property = value; }
}
}
public class XCollection : List<X>
{
private bool ItemExists(string stringProperty)
{
X found = Find(item => item.Property == stringProperty);
return found.Property != null ? true : false;
}
}
Changing the collection class declaration to public class XCollection : List<X?> screws it up!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Then put an additional check for null in the lambda expression
item => (item == null) ? false : item.Property == stringProperty
|
|
|
|
|
Also, your stuct is mutable, this will cause you additional problems because the instances of the struct are copied rather than referenced you may be making changes to a copy rather than the original and the functionality may not be desired.
You should make your struct immutable by removing any setters and methods that modify the internal state once it is created.
|
|
|
|
|
Thanks for the advice but I need the struct to be mutable in this situation.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Then you would be better changing it to a class.
|
|
|
|
|
The struct could have a static member to use in that case, kinda like String.Empty and Guid.Empty
|
|
|
|
|
Doh! That hadn't crossed my mind - thanks
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|