Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Cannot implicitly convert type 'object' to 'System.ServiceModel.PeerNodeAddress'.An explicit conversion exists (are you missing a cast?)

 
 
Old 12-28-2007   #1 (permalink)
drmcgee2000


 
 

Cannot implicitly convert type 'object' to 'System.ServiceModel.PeerNodeAddress'.An explicit conversion exists (are you missing a cast?)

Greetings,

I have built a WCF client with a custom peer resolver as a chat
application. The code for both applications (client and server) work
fine, and I am able to resolve clients through the Resolver Contract;
HOWEVER, I am not sure what to pass to register the clients using the
Regeister method with parameters "MeshId" and "PeerNodeAddress".

In my research I know the the PeerNodeAddress is encapsulated in a
seal class PeerNodeAddress. I have searched the Internet for an
example of what the PeerNodeAddress would look like as a passed
parameter, but there is nothing out there.

My question:

When I call the Register method to register my client with the server
what am I passing? Am I passing the IP Address of the client? If so,
how would I cast the IPAddress type into a PeerNodeAddress? Does
anyone have a working example?

Here is the error message I get when I try to assign the client IP
address:

<code>

PeerNodeAddress nodeAddress;

IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress address in ips.AddressList)
{
if (address.AddressFamily ==
System.Net.Sockets.AddressFamily.InterNetwork)
nodeAddress = address as PeerNodeAddress;
}

<error>

Cannot implicitly convert type 'object' to
'System.ServiceModel.PeerNodeAddress'. An explicit conversion exists
(are you missing a cast?)

Question, what is the correct cast?



My System SpecsSystem Spec
Old 12-28-2007   #2 (permalink)
drmcgee2000


 
 

Re: Cannot implicitly convert type 'object' to 'System.ServiceModel.PeerNodeAddress'.An explicit conversion exists (are you missing a cast?)

On Dec 28, 9:57*am, drmcgee2...@xxxxxx wrote:
Quote:

> Greetings,
>
> I have built a WCF client with a custom peer resolver as a chat
> application. The code for both applications (client and server) work
> fine, and I am able to resolve clients through the Resolver Contract;
> HOWEVER, I am not sure what to pass to register the clients using the
> Regeister method *with parameters "MeshId" and "PeerNodeAddress".
>
> In my research I know the the PeerNodeAddress is encapsulated in a
> seal class PeerNodeAddress. I have searched the Internet for an
> example of what the PeerNodeAddress would look like as a passed
> parameter, but there is nothing out there.
>
> My question:
>
> When I call the Register method to register my client with the server
> what am I passing? Am I passing the IP Address of the client? If so,
> how would I cast the IPAddress type into a PeerNodeAddress? Does
> anyone have a working example?
>
> Here is the error message I get when I try to assign the client IP
> address:
>
> <code>
>
> PeerNodeAddress nodeAddress;
>
> IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());
> foreach (IPAddress address in ips.AddressList)
> {
> * * *if (address.AddressFamily ==
> System.Net.Sockets.AddressFamily.InterNetwork)
> * * * * * nodeAddress = *address as PeerNodeAddress;
>
> }
>
> <error>
>
> Cannot implicitly convert type 'object' to
> 'System.ServiceModel.PeerNodeAddress'. An explicit conversion exists
> (are you missing a cast?)
>
> Question, what is the correct cast?
OK, I solved the issue, and for anyone whom comes accross the same
issue, here is my fix.

In my code above I was trying to do a simple assignment; however, this
is not possible because no cast is possible because the
PeerNodeAddress is a sealed class.

Therefore, if you instantiate a new nodeAddress with a new
implementation of the Service Endpoint, you can then pass the
AddressList from the IPAddress object and the code works wonderfully.

Hope this helps you.

<code>

foreach (IPAddress address in ips.AddressList)
{
if (address.AddressFamily ==
System.Net.Sockets.AddressFamily.InterNetwork)
{
ReadOnlyCollection<IPAddress> ip = new
ReadOnlyCollection<IPAddress>(ips.AddressList);
nodeAddress = new PeerNodeAddress(new
EndpointAddress("http://137.51.145.137:8001/servicemodel/service"),
ip);

}
}
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Object cast exception at runtime .NET General
Object cast error in runtime .NET General
Type cast PowerShell
Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]' .NET General
implicit/explicit data type conversion? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46