Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service reference not generating client types

I am trying to consume a WCF service in a class library by adding a service reference to it. In one of the class libraries it gets consumed properly and I can access the client types in order to generate a proxy off of them. However in my second class library (or even in a console test app), when i add the same service reference, it only exposes the types that are involved in the contract operations and not the client type for me to generate a proxy against.

e.g. Endpoint has 2 services exposed - ISvc1 and ISvc2. When I add a service reference to this endpoint in the first class library I get ISvc1Client andf ISvc2Client to generate proxies off of in order to use the operations exposed via those 2 contracts. In addition to these clients the service reference also exposes the types involved in the operations like (type 1, type 2 etc.) this is what I need. However when i try to add a service reference to the same endpoing in another console application or class library only Type 1, Type 2 etc. are exposed and not ISvc1Client and ISvc2Client because of which I cannot generate a proxy to access the operations I need. I am unable to determine why the service reference gets properly generated in one class library but not in the other or the test console app.

like image 882
Cranialsurge Avatar asked Jun 08 '10 18:06

Cranialsurge


People also ask

What is difference between web reference and service reference?

The service reference is the newer interface for adding references to all manner of WCF services (they may not be web services) whereas Web reference is specifically concerned with ASMX web references. You can access web references via the advanced options in add service reference (if I recall correctly).

How do I set up a service reference?

To access the Configure Service Reference dialog box, right-click a service reference in Solution Explorer and choose Configure Service Reference. You can also access the dialog box by clicking the Advanced button in the Add Service Reference Dialog Box.

What is a Web service reference?

The WCF Web Service Reference tool retrieves metadata from a web service in the current solution, on a network location, or from a WSDL file, and generates a source file containing Windows Communication Foundation (WCF) client proxy code that your . NET app can use to access the web service.


1 Answers

You may have selected Reuse types in specified reference assemblies but not chosen the very important mscorlib library.

First click 'Show All Files' at the top of your Solution Explorer so you can expand out the service reference.

enter image description here

  • Find the Reference.cs file and open it.
  • Search for ClientBase in the source code to make sure you really haven't generated a client with a name you weren't expecting. If you find it then that's the name of your service client.

enter image description here

If nothing matches then right click the service reference and choose Configure Service Reference.

The important one is mscorlib which is required to properly generate the client. I like to select System.Xml.Linq also to get nice Linq classes like XElement and not XmlElement.

enter image description here


Still stuck?

  • Tip: I always prefer to create a dedicated DLL just for the service reference. It can help if you need to wipe it out and start over, and it avoids certain chicken-and-egg compile problems once in a while.

  • If you end up with half a References.cs file you may be 'reusing a referenced type' that is not compatible with your data contract. i.e. you've added data members on the server side, or changed the signature of an existing member such as making a value type optional.

  • First, realize that SVCUTIL will quite happily generate an incomplete output file even if it has problems, and when running from Visual Studio you don't get the log file. Keep an eye in Explorer for the expected size and compare it to your 'last known good' size.

  • Try to run SVCUTIL.EXE directly from a batch file (remember to save this file for next time)

  • This is easiest to do in a Visual Studio Command prompt

  • Sample command is as follows, note the reference parameter to the DLL that you are referencing types from.

    svcutil.exe http://dev.example.com/SSWPF.Web/Services/SS.svc /reference:bin\debug\RRStore.Sys.DLL

Detail: An exception was thrown while running a WSDL import extension: 

System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Referenced type 'SS.Sys.ShippingRateInfo, RRStore.Sys, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'ShippingRateInfo' in namespace 'http://schemas.datacontract.org/2004/07/SS.Sys' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISSWCF']

Fortunately the answer here was simple, my type ShippingRateInfo had changed and I hadn't updated it. Once I copied this type over from the server everything compiled just fine (I chose to revert back to VS tool).

like image 130
Simon_Weaver Avatar answered Oct 06 '22 21:10

Simon_Weaver