CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    WCF Service Tutorial question

    Trying to enhance my skills, I tried to build a WCF Service following the steps of the tutorial provided by M$:

    http://msdn.microsoft.com/en-us/library/ms733133.aspx

    All seemed to go well up until the time that I was supposed to use svcutil.exe tool. Using the command prompt that M$ provided
    Code:
    svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service
    which is supposed to generate the proxy code for the client, I instead received one of my old favorites:
    Code:
    'svcutil.exe' is not recognized as an internal or external command,
    operable program or batch file.
    A search of my VS 2008 directories failed to find svcutil.exe. Little wonder it didnt work. But it should be there somewhere, shouldnt it?

    Any clues would be helpful.

    Edit: Well, I found it. It was right where M$ said it would be.
    http://msdn.microsoft.com/en-us/library/aa347733.aspx

    Question now is (and it's an old one for me): How do I set the path so that from a command prompt anywhere in the directory system, the OS will know how to find svcutil.exe ? (Or any other thing I wish to 'add to the path' for that matter. I'm ashamed to admit it, but I've always wondered how to do that.)

    Edit: OK. I found out how to access Environment Variables in VISTA. There are two ways to do this.

    The easy way:

    1.Click Start and choose Control Panel
    2.In the Search box on the top right of the window type “system path” (no quotes)
    3.Click “Edit the system environment variables”
    4.Begin at step 4 below.

    The hard way:

    1.Click Start and choose Control Panel
    2.Click System, on the right you’ll see “View basic information about your computer”
    3.On the left is a list of tasks, the last of which is “Advanced system settings.” Click that.
    4.The Advanced tab of the System Properties dialog box is shown. Click the Environment Variables button on the bottom right.
    5.In the lower box titled “System Variables” scroll down to Path and click the Edit button.
    6.Change your path as need be.
    7.Restart your system. Vista didn’t pick up the system path environment variable change until I restarted.

    THEN WHAT ? How do you actually add a target directory or app? I need an example.
    Last edited by Mike Pliam; February 25th, 2010 at 02:38 AM.
    mpliam

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: WCF Service Tutorial question

    I saw you found it by yourself. The idea is that svcutil.exe is distributed with the Windows SDK. To be able to run it from everywhere, add the folder where it's located to the PATH environment variables.

    THEN WHAT ? How do you actually add a target directory or app? I need an example
    Add to what?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    May 2002
    Posts
    1,798

    Re: WCF Service Tutorial question

    OK. Just pasted the path in a new User Environment variable. But still have a problem with VISTA.

    Ran the Microsoft Visual Studio 2008 tool Command Prompt as 'Administrator' (with Administrator privileges). But something is amiss.

    Code:
    C:\Users\mbpliam\Documents\Visual Studio 2008\Projects\SERVICES\Service\Client>s
    vcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localho
    st:8000/ServiceModelSamples/service
    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Attempting to download metadata from 'http://localhost:8000/ServiceModelSamples/
    service' using WS-Metadata Exchange or DISCO.
    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Error: Cannot obtain Metadata from http://localhost:8000/ServiceModelSamples/ser
    vice
    
    If this is a Windows (R) Communication Foundation service to which you have acce
    ss, please check that you have enabled metadata publishing at the specified addr
    ess.  For help enabling metadata publishing, please refer to the MSDN documentat
    ion at http://go.microsoft.com/fwlink/?LinkId=65455.
    
    
    WS-Metadata Exchange Error
        URI: http://localhost:8000/ServiceModelSamples/service
    
        Metadata contains a reference that cannot be resolved: 'http://localhost:800
    0/ServiceModelSamples/service'.
    
        Could not connect to http://localhost:8000/ServiceModelSamples/service. TCP
    error code 10061: No connection could be made because the target machine activel
    y refused it 127.0.0.1:8000.
    
        Unable to connect to the remote server
    
        No connection could be made because the target machine actively refused it 1
    27.0.0.1:8000
    
    
    HTTP GET Error
        URI: http://localhost:8000/ServiceModelSamples/service
    
        There was an error downloading 'http://localhost:8000/ServiceModelSamples/se
    rvice'.
    
        Unable to connect to the remote server
    
        No connection could be made because the target machine actively refused it 1
    27.0.0.1:8000
    
    If you would like more help, type "svcutil /?"
    
    C:\Users\mbpliam\Documents\Visual Studio 2008\Projects\SERVICES\Service\Client>
    Any idea what I have done wrong?

    Edit: Sorry! I forgot that I had to run the service before attempting to use svcutil.exe. Of course, everything has to be Run as Administrator on VISTA. Then it worked just as M$ said it would. Looks like this whent it works, and generates an app.config and generatedProxy.cs files

    Code:
    C:\Users\mbpliam\Documents\Visual Studio 2008\Projects\SERVICES\Service\Client>s
    vcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localho
    st:8000/ServiceModelSamples/service
    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Attempting to download metadata from 'http://localhost:8000/ServiceModelSamples/
    service' using WS-Metadata Exchange or DISCO.
    Generating files...
    C:\Users\mbpliam\Documents\Visual Studio 2008\Projects\SERVICES\Service\Client\g
    eneratedProxy.cs
    C:\Users\mbpliam\Documents\Visual Studio 2008\Projects\SERVICES\Service\Client\a
    pp.config
    I only post all this here in case it might help some others because there are alot of negative Community Responses on this tutorial (which is actually quite good provided one reads it carefully and follows the instructions).
    Last edited by Mike Pliam; February 25th, 2010 at 02:22 PM. Reason: OOOPS
    mpliam

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: WCF Service Tutorial question

    This article is a bit out of date because there really isn't any need to generate a proxy from the command line. The way to generate the proxy in VS2008, is to right click on the project in the solution explorer and choose "Add Service Reference...". You'll need to run VS as an admin as well.

    On Win 7, you need to adjust permissions to get the service to run.

    // HTTP could not register URL http://+:<port>/<servicename>/.
    // Your process does not have access rights to this namespace
    // (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).


    Welcome to the world of WCF - 'M$' has done a great job of it.


    Tip: If you control both the service code and the client code, then you may not want to use a proxy anyway.
    Last edited by Arjay; February 26th, 2010 at 12:28 AM.

  5. #5
    Join Date
    May 2002
    Posts
    1,798

    Re: WCF Service Tutorial question

    Thanks for the advice, Arjay. I agree, this is really great technology. There is a note in the tutorial suggesting an alternative to running a proxy from the command line. I just havnt tried it yet.

    BTW, my interest in this was stimulated by a comment that you had made some time ago about using a service to monitor a network share application in the event of an appcrash. I presume that this type of application is what is needed. The next question is how to code such a service? Does the target app (to be monitored) have to be a client of the service, or is there some other model?
    mpliam

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: WCF Service Tutorial question

    Quote Originally Posted by Mike Pliam View Post
    Thanks for the advice, Arjay. I agree, this is really great technology. There is a note in the tutorial suggesting an alternative to running a proxy from the command line. I just havnt tried it yet.
    Essentially in the 'proxy-less' approach, you pull out the interface and contracts out of the WCF service project and put them into a separate class library. Then you include references of the library in the service and client projects. On the client you use the ChannelFactory (or DuplexChannelFactory) class to connect to the client.

    I have a little templated class that wraps these classes to allow the following:

    Code:
    var client = ChannelProxy<IMyService>.Open( Constants.Configs.MyServiceConfig );
    
    The advantage of the proxyless approach is that the client doesn't need to do any 'conversions' that you need to sometimes have to do when the proxy generates a different namespace than other shared objects. It greatly simplifies the code if you can do without the proxy (of course, if you don't own both the server and client code, you can't do this).

    Quote Originally Posted by Mike Pliam View Post
    BTW, my interest in this was stimulated by a comment that you had made some time ago about using a service to monitor a network share application in the event of an appcrash. I presume that this type of application is what is needed. The next question is how to code such a service? Does the target app (to be monitored) have to be a client of the service, or is there some other model?
    There are several approaches. One approach is to have the application to be monitored send 'ping alive' notifications to the WCF service. Inside the service, you'll check for a last received alive ping and if it's been longer than your specified timeout, you know something has happened to the app. If you can't modify the client application, you can use another approach where a service on the client machine monitors the status of the application (using the process class). It then sends status info back to the main service using WCF. I'm sure there are plenty of other approaches as well - it really depends on what you need.

  7. #7
    Join Date
    May 2002
    Posts
    1,798

    Re: WCF Service Tutorial question

    I have a little templated class that wraps these classes to allow the following
    Would you be willing to post or send me an service and client example of your approach ? mbpliam@pliatech.com
    mpliam

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: WCF Service Tutorial question

    I'm currently writing an article about using WCF to communicate between a Windows Service and Taskbar client app.

    The ChannelProxy class (and other utility classes) will be included in the article source.

    Stay tuned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured