locked
Error "cannot import wsdl:portType" when generating service references RRS feed

  • Question

  • Our self-hosted WCF service makes extensive use of the Entity Framework, and uses EF-generated classes for transferring data.  This worked reasonably well under .NET 3.5 SP1.  However, at some point after upgrading to .NET 4.0, we're having trouble generating service references correctly.  Specifically, if we try to share the EF assembly between the client and the server, svcutil.exe won't generate the proxy classes.  Specifically, this command-line:

    svcutil /r:SlideLinc.Model.dll http://localhos51151/RoomService/

    Will give us these errors:

    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30128.1]
    Copyright (c) Microsoft Corporation. All rights reserved.

    Attempting to download metadata from 'http://localhost:51151/RoomService/' using WS-Metadata Exchange or DISCO.
    Error: Cannot import wsdl:portType
    Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
    Error: Referenced type 'SlideLinc.Model.PolylinePoint, SlideLinc.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'PolylinePoint' in namespace 'http://schemas.datacontract.org/2004/07/SlideLinc.Model' 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://service.slidelinc.com/']/wsdl:portType[@name='IRoomService']

    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://service.slidelinc.com/']/wsdl:portType[@name='IRoomService']
    XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='CustomBinding_IRoomService']


    Error: Cannot import wsdl:port
    Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
    XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='CustomBinding_IRoomService']
    XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='RoomService']/wsdl:port[@name='CustomBinding_IRoomService']


    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://service.slidelinc.com/']/wsdl:portType[@name='IRoomService']
    XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='CustomBinding_IRoomService1']


    Error: Cannot import wsdl:port
    Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
    XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='CustomBinding_IRoomService1']
    XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='RoomService']/wsdl:port[@name='CustomBinding_IRoomService1']

    Now, my understanding was that the EF-generated classes (such the PolylinePoint class referred to in the error above) were supposed to be WCF proxy friendly, so I'm not sure why it's throwing an exception.  And more to the point, I don't know what about it is causing the problem.  Here's the class in question:

        [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="PolylinePoint", Namespace="http://schemas.datacontract.org/2004/07/SlideLinc.Model", IsReference=true)]
    [System.SerializableAttribute()]
    public partial class PolylinePoint : Alanta.Test.RoomService.EntityObject {

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private int OrderField;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private System.Guid PolylinePointIdField;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private Alanta.Test.RoomService.WhiteboardShapePolyline WhiteboardShapePolylineField;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private Alanta.Test.RoomService.EntityReferenceOfWhiteboardShapePolylineE91PxI9v WhiteboardShapePolylineReferenceField;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private double XField;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private double YField;

    [System.Runtime.Serialization.DataMemberAttribute()]
    public int Order {
    get {
    return this.OrderField;
    }
    set {
    this.OrderField = value;
    }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public System.Guid PolylinePointId {
    get {
    return this.PolylinePointIdField;
    }
    set {
    this.PolylinePointIdField = value;
    }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public Alanta.Test.RoomService.WhiteboardShapePolyline WhiteboardShapePolyline {
    get {
    return this.WhiteboardShapePolylineField;
    }
    set {
    this.WhiteboardShapePolylineField = value;
    }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public Alanta.Test.RoomService.EntityReferenceOfWhiteboardShapePolylineE91PxI9v WhiteboardShapePolylineReference {
    get {
    return this.WhiteboardShapePolylineReferenceField;
    }
    set {
    this.WhiteboardShapePolylineReferenceField = value;
    }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public double X {
    get {
    return this.XField;
    }
    set {
    this.XField = value;
    }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public double Y {
    get {
    return this.YField;
    }
    set {
    this.YField = value;
    }
    }
    }

    Which results in this WSDL:

    <xs:complexType name="ArrayOfPolylinePoint">
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="unbounded" name="PolylinePoint" nillable="true" type="tns:PolylinePoint" /> 
    </xs:sequence>
    </xs:complexType>
    <xs:element name="ArrayOfPolylinePoint" nillable="true" type="tns:ArrayOfPolylinePoint" /> 
    <xs:complexType name="PolylinePoint">
    <xs:complexContent mixed="false">
    <xs:extension base="q14:EntityObject" xmlns:q14="http://schemas.datacontract.org/2004/07/System.Data.Objects.DataClasses">
    <xs:sequence>
    <xs:element minOccurs="0" name="Order" type="xs:int" /> 
    <xs:element minOccurs="0" name="PolylinePointId" type="ser:guid" /> 
    <xs:element minOccurs="0" name="WhiteboardShapePolyline" nillable="true" type="tns:WhiteboardShapePolyline" /> 
    <xs:element minOccurs="0" name="WhiteboardShapePolylineReference" nillable="true" type="q14:EntityReferenceOfWhiteboardShapePolylineE91PxI9v" /> 
    <xs:element minOccurs="0" name="X" type="xs:double" /> 
    <xs:element minOccurs="0" name="Y" type="xs:double" /> 
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    <xs:element name="PolylinePoint" nillable="true" type="tns:PolylinePoint" /> 

    That all seems fairly standard: the class isn't doing any funky inheritance from anything, it's not using generic lists of generics, or anything else that has been documented to cause this error.  It kind of has me baffled.

    Apart from the fairly obvious observation that MS has really horrible tools for troubleshooting problems like this (it's taken me hours of scratching my head to get from "Why is my reference.cs file empty?" to the above description of the problem), anybody have any suggestions for troubleshooting this?


    Ken Smith
    Tuesday, March 30, 2010 11:51 PM

Answers

  • Yeah, the Add Service Reference has the same problem, except with the not-terribly-helpful difference that it doesn't bother to tell you that it had a problem: it just doesn't generate the code.  (I wonder whose design decision that was . . . and they've had something like three years to fix that problem.)

    I actually have filed a Connect bug (https://connect.microsoft.com/VisualStudio/feedback/details/545847/add-service-reference-fails-to-generate-reference-cs-file-correctly), but I haven't heard back anything yet.  If I hear anything interesting, I'll post it here.


    Ken Smith
    Wednesday, March 31, 2010 12:06 AM

All replies

  • Have you tried using Add Service Reference? Does that work? Also, did you change anything in your project after you upgraded to .NET 4? You may also want to file a Connect bug about this.

     

    Wednesday, March 31, 2010 12:00 AM
    Moderator
  • Yeah, the Add Service Reference has the same problem, except with the not-terribly-helpful difference that it doesn't bother to tell you that it had a problem: it just doesn't generate the code.  (I wonder whose design decision that was . . . and they've had something like three years to fix that problem.)

    I actually have filed a Connect bug (https://connect.microsoft.com/VisualStudio/feedback/details/545847/add-service-reference-fails-to-generate-reference-cs-file-correctly), but I haven't heard back anything yet.  If I hear anything interesting, I'll post it here.


    Ken Smith
    Wednesday, March 31, 2010 12:06 AM
  • At which machine did you start svcutil?
    Has this machine .NET RC installed?
    Did you try it at the same machine wher the service is running?

    Saturday, April 3, 2010 1:17 PM
  • The machine on which I started svcutil.exe was the same machine on which the service was running (i.e., my local dev box).  This machine has the RC drop for .NET and VS2010 installed.

    I put together a stand-alone solution for MS that repro'd the problem consistently on my machine, but they weren't able to reproduce it internally on the VS2010/.NET RTM version.  So I'll try it again as soon as I can get my hands on 30319.1 :-).


    Ken Smith
    Thursday, April 8, 2010 4:20 AM