p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Professional WCF 4: Windows Communication Foundation with .NET 4 (http://p2p.wrox.com/book-professional-wcf-4-windows-communication-foundation-net-4-589/)
-   -   Generating Client Code (http://p2p.wrox.com/book-professional-wcf-4-windows-communication-foundation-net-4/82025-generating-client-code.html)

argyleghost December 24th, 2010 09:21 AM

Generating Client Code
I am stuck on Step 4 on page 42 (Chpt.2) It says to use the svcutil or the reference service option to generate the client code. But, I ran the svcutil in the previous step and generated the three files, but what do I do with them now? It doesnt state how exactly one uses these files to generate the proxy for the client. I am stumped. Please help!!!

BTW, I created a new project for the client (seperate from the service class). Also in the figure 2.6 Client Code where is this assembly:

using Wrox.CarRentalService.ConsoleClient.CarRentalProxy ;

It never mentions creating this assembly anywhere in the book. But now it says to reference it? Whats in this file and how does it relate to the client code. Tried for 2 days trying to figure this out. PLEASE HELP!! Thank you in advanced. Have a merry xmas and happy holidays all.
-Argbyle Ghost

Fabio.Cozzolino December 24th, 2010 02:06 PM

Hi Argbyle Ghost,

the svcutil.exe command line generate a source code file and a config file. Then, you can include them in your project and use to call the remote service:

1. Use svcutil to generate files. Example: svcutil.exe <wsdl> /n:*,Wrox.CarRentalService.ConsoleClient.CarRentalP roxy
2. Include the generate .cs and merge the .config with the project's .config (web.config or app.config)
3. Use the proxy :)


argyleghost December 24th, 2010 11:10 PM

Thanks, but still having issues with this.
Thanks for the quick reply Fabio. unfortunately I still can not get (more like understand what is going on) it to work. a little backround. I have 2 projects:
1. CarRentalService (Which contains the ICarRental interface and the class that incorporates the interface for the inner workings,)
2. CarRentalClientConsole. This is the client Which will call the service.

from the VS command prompt running as administrator I ran:
C:\inetpub\wwwroot\CarRentalService\CarRentalServi ce\bin>svcutil.exe CarService.wsdl /n:*,Wrox.CarRentalService.ConsoleClient.CarRentalP roxy

(There is already three files from running the svcutil.exe from earlier that I renamed (not the extension)in this directory to CarService.wsdl, CarService.xsd, and I kept the file named the same for schema.microsoft.com.2003.10.Serialization.xsd)

and I recieved the following error:

c:\inetpub\wwwroot\CarRentalService\CarRentalService\bin>svcutil.exe CarService.wsdl /n:*,Wrox.CarRentalService.ConsoleClient.CarR
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessa
Error: Schema with target namespace 'http://localhost:8080/' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://localhost:8080/']/wsdl:portType[@name='ICarRentalService']

Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://localhost:8080/']/wsdl:portType[@name='ICarRentalService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://localhost:8080/']/wsdl:binding[@name='DefaultBinding_ICarRental

Generating files...
Warning: No code was generated.
If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servi
or because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata docum
ents to the tool.

Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.

What am I missing here? I am new to WCF Services and I am quite confused as to what I am doing wrong ...and how to fix.
I hope the code helps you see where I might be going wrong.
Merry xmas,
Argyle Ghost

argyleghost December 28th, 2010 06:52 AM

Still need help
Still need help .... Anyone.... anyone.....

Fabio.Cozzolino December 28th, 2010 07:49 AM

Hi Argbyle Ghost,

sorry for the late response. Try this:

svcutil.exe *.wsdl *.xsd /n:*,Wrox.CarRentalService.ConsoleClient.CarRentalP roxy


argyleghost December 28th, 2010 07:36 PM

OK, getting closer... :D
Thanks for the replies and help Fabio.
I just deleted the 3 previous files that were generated from the bin folder. ran the svcutil.exe on the Contracts.dll and it generated the three files again.

I then took your last code and generated the two files (Schema.cs and the output.config). Looking in the schema.cs I saw that there is a namesspace:

namespace Wrox.CarRentalService.ConsoleClient.CarRentalProxy
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "")]
    public interface ICarRentalService
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICarRentalService/CalculatePrice", ReplyAction="http://tempuri.org/ICarRentalService/CalculatePriceResponse")]
        double CalculatePrice(System.DateTime pickupDate, System.DateTime returnDate, string pickupLocation, string vehiclePreference);

two things now (which are not explained at all in the book).
1. [QUESTION] How did it know in the namespace to put "...consoleclient.CarRentalProxy"? I checked for code all over the Carservice app and there is nothing there referencing such client. I have the ClientConsole in a totally seperate solution. How did it know?

2. [WHAT I DID - WAS IT THE RIGHT WAY?] I created an app.config in the client Console app and copied and pasted the "output.config" in it. Then I created an ICarRentalService.cs file in the Console Client and copy and pasted the schema.cs file there.

Ran the code and the console did come up (finally! Thanks Fabio!). I did run into an Invalid Operation Exception error: "The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified."

But at least the console started to run. Wrox really needs to update this section of the book. It scares me what assumptions they left for the other 900 pages. :D

argyleghost December 29th, 2010 08:42 AM

I see it got the name from the svcutil command. Hehehehe, thanks. It just dawned on me.

All times are GMT -4. The time now is 12:57 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.