What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType"
Asked Answered
P

13

88

I created a WCF service library project in my solution, and have service references to this. I use the services from a class library, so I have references from my WPF application project in addition to the class library. Services are set up straight forward - only changed to get async service functions.

Everything was working fine - until I wanted to update my service references. It failed, so I eventually rolled back and retried, but it failed even then! So - updating the service references fails without doing any changes to it. Why?!

The error I get is this one:

Custom tool error: Failed to generate code for the service reference 
'MyServiceReference'.  Please check other error and warning messages for details.   

The warning gives more information:

Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: 
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: List of referenced types contains more than one type with data contract name 'Patient' in  
namespace 'http://schemas.datacontract.org/2004/07/MyApp.Model'. Need to exclude all but one of the 
following types. Only matching types can be valid references: 
"MyApp.Dashboard.MyServiceReference.Patient, Medski.Dashboard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
"MyApp.Model.Patient, MyApp.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISomeService']

There are two similar warnings too saying:

Custom tool warning: 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://tempuri.org/']/wsdl:portType[@name='ISomeService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_ISomeService']  

And the same for:

Custom tool warning: Cannot import wsdl:port .. 

I find this all confusing.. I don't have a Patient class on the client side Dashboard except the one I got through the service reference. So what does it mean? And why does it suddenly show? Remember: I didn't even change anything!

Now, the solution to this was found here, but without an explanation to what this means. So; in the "Configure service reference" for the service I uncheck the "Reuse types in the referenced assemblies" checkbox. Rebuilding now it all works fine without problems. But what did I really change? Will this make an impact on my application? And when should one uncheck this? I do want to reuse the types I've set up DataContract on, but no more. Will I still get access to those without this checked?

Pressing answered 9/12, 2009 at 10:5 Comment(1)
Ok, there is a short explanation on msdn (msdn.microsoft.com/en-us/library/bb628653.aspx). But does anyone have a better explanation? How do this refer to the DataContract's I set up?Pressing
C
38

When you add a service reference, there are two ways the types that are used by the service can be handled:

  • The types are stored in a dll, and that dll is referenced from both the client and the server application.
  • The types are not in a dll referenced by the client. In that case the tool that creates the service reference, will create the types in the references.cs file.

There are many things that can go wrong. We have found that if the tool crashes, it is sometimes faster to delete the service reference and start again.

We have stopped using service reference. For projects where we have control of the client and the service, we use the method described in this screencast.

Clinkerbuilt answered 10/12, 2009 at 18:43 Comment(2)
Thanks! I actually found that screencast yesterday. Watched it, and it was truelly an eye opener! Am planning to move to that structure once I get the basics in place. Sounds like you've been struggeling with some of the same problems I'm seeing. I too often end up deleting and readding the service references when something oddly goes wrong, and that's not a good sign.. Hoping the described architecture will help!Pressing
Has anyone been able to write the web service by hand when you are using a PollingDuplex Binding with Silverlight 5?Clef
H
159

I found my answer here: http://www.lukepuplett.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html

Long story short: I unchecked Reuse types in reference assemblies from the Advanced menu.


I don't know if this matters but i'm not using MVC, but Web Forms.

Hypersensitize answered 23/5, 2011 at 12:49 Comment(6)
A restart of VS 2012 is also requiredFreezedrying
Interested to watch, but the link is now dead, please share if you have it elsewhereDeveloping
Works in an MVC 3 project under VS2013 (no restart required).Ostracod
+1 - Just for reference: To make this change, right-click on the service reference in the project that consumes it and select 'Configure Service Reference...'Washable
Nothing is better then "long story short" :)Lilly
This is exactly the solution I needed. Was using a service reference for a 3rd party company, and while it worked in their test app, it would not work in our production application. As soon as I unchecked "reuse types", everything started working.Bloodshot
C
38

When you add a service reference, there are two ways the types that are used by the service can be handled:

  • The types are stored in a dll, and that dll is referenced from both the client and the server application.
  • The types are not in a dll referenced by the client. In that case the tool that creates the service reference, will create the types in the references.cs file.

There are many things that can go wrong. We have found that if the tool crashes, it is sometimes faster to delete the service reference and start again.

We have stopped using service reference. For projects where we have control of the client and the service, we use the method described in this screencast.

Clinkerbuilt answered 10/12, 2009 at 18:43 Comment(2)
Thanks! I actually found that screencast yesterday. Watched it, and it was truelly an eye opener! Am planning to move to that structure once I get the basics in place. Sounds like you've been struggeling with some of the same problems I'm seeing. I too often end up deleting and readding the service references when something oddly goes wrong, and that's not a good sign.. Hoping the described architecture will help!Pressing
Has anyone been able to write the web service by hand when you are using a PollingDuplex Binding with Silverlight 5?Clef
C
10

I also had this issue Today. It took me one entire day to find my mistake. Hope it helps.

My class that weren't able to be imported has a cutom enum type property. This property is marked as DataMember and the Enum is also marked as DataContract. Everything fine so far. I just forgot to mark every enum member as EnumMember.

So i changed

[DataContract]
public enum SortMethodType
{
    Default = 0,
    Popularity = 1,
    ReleaseDate = 2,
    PublishedDate = 3,
    TranslatedTitle = 4,
    OriginalTitle = 5,
    UserRating = 6,
    Duration = 7
}

To this:

[DataContract]
public enum SortMethodType
{
    [EnumMember]
    Default = 0,
    [EnumMember]
    Popularity = 1,
    [EnumMember]
    ReleaseDate = 2,
    [EnumMember]
    PublishedDate = 3,
    [EnumMember]
    TranslatedTitle = 4,
    [EnumMember]
    OriginalTitle = 5,
    [EnumMember]
    UserRating = 6,
    [EnumMember]
    Duration = 7
}

And it finally worked!

Conformity answered 12/5, 2011 at 19:30 Comment(0)
D
8

Go to Advanced properties while adding reference and remove "System.Window.Browser" from the checklist, It solves the problem.

Delwyn answered 16/3, 2010 at 18:59 Comment(1)
Thx! Not using Service References anymore - doing the manual approach described in the screencast from the answer by @Shiraz. But this is nice to know anyway!Pressing
E
8

that might sound weird, but I got it fixed by deleting the references, then closing Visual Studio, and reopening it again, and finally adding the references again.

I think the custom tool thing needed to be restarted or something.

Evalyn answered 3/12, 2011 at 18:24 Comment(1)
even if you are determined to figure out the problem WITHOUT deleting the reference I strongly recommend you create a NEW PROJECT and add the reference to see if it works. this may reveal an error you don't see in your existing project or it may just workJumna
I
4

I constantly run across this error while it works on another developers machine. Even though I'm a full admin everywhere in my virtual machine, I tried closing Visual Studio, and re-opening with 'Run As Administrator' and it magically worked.

Good luck.

Insane answered 22/8, 2012 at 13:25 Comment(0)
L
4

I got the warning after upgrading my solution from Visual Studio (VS) 2010 to 2013 and changing each project's .NET Framework from 4 to 4.5.1. I closed VS and re-opened and the warnings went away.

Laboratory answered 6/4, 2016 at 16:9 Comment(1)
This helped me, but I changed from .NET 4.5.2 to 4.6 Gaa!Bashan
I
2

One downside of turning off 'reuse types in referenced assemblies' is that it can cause issues with ambiguous references. This is due to the service reference creating those objects again in the reference .cs file, and your code implementing the service may be referencing them from the original namespace.

When this scenario occurs I find it useful to check the 'reuse types in specified referenced assemblies' which allows me to choose the ones with ambiguous references only, which resolves the issue quickly that way.

Hope it helps someone else.

Incubate answered 5/2, 2014 at 1:40 Comment(0)
P
0

My interfaces of the WCF service are in an assembly, the implementation is in an another and the service reference is in yet another assembly, separate from the clients of the service reference. I got the error message right after I applied the DataContract to an enum. After I applied EnumMember to the fields of the enum, the issue resolved.

Pallid answered 10/8, 2011 at 22:17 Comment(0)
J
0

If in doubt that your service doesn't have any problems (such as problems with enums, or non-serializable classes as mentioned by others) then try to create a new project with a new reference.

I am using Silverlight 5 and I had tried to delete and recreate the reference several times. The reference.cs file just came up completely empty each time and it had been literally years since I'd created it so trying to figure out what had changed in the service was out of the question.

I noticed that the error contained references to 2.0.5.0. Now I don't even know if this is actually relevant to the Silverlight version, but it made me think of just creating a brand new project and then suddenly everything worked.

Warning 2 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Could not load file or assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified. XPath to Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:port Type[@name='IShoppingCart']

Jumna answered 24/7, 2013 at 0:2 Comment(0)
G
0

I was looking over my project and I was having this same issue. It turned out to be different versions of the same DLL on the WCF vs. Web Site. Web site had a newer version of the DLL and the service was referencing an older version of the DLL. Once they were all in sync all worked well.

Gomer answered 21/11, 2013 at 14:22 Comment(0)
Y
0

I experienced the same error. I struggled for almost a day trying to find out what was going wrong. The clue for me were the warnings that VS was throwing. It was trying to do some kind of mapping to Yahoo.Yui.Compressor.dll, a library I had added and removed (because I decided not to use it) a couple of days before. It was shocking because the library wasn't there, but somehow it was trying to reference it.

Finally, I restore this dll from the Trash, and then I could update my service reference successfully.

Yonkers answered 11/3, 2014 at 14:17 Comment(0)
M
0

For anyone here in the future, I had the same error but caused by version issues, in two different ways.

I have two WCF services and two client applications that talk via the service references. I updated a nuget package on both sides and tried to update the service reference and got this error.

Deleting didn't help. Unchecking "reuse assemblies" is not desired as I need to reuse them - that's the whole point.

In the end, there were two separate issues:

1) The first issue, I believe, was a visual studio caching issue. I meticulously went over all of the references and found no issues but it still reported being unable to find the previous version of the file. I uninstalled all of the nuget packages, restarted visual studio, and reinstalled them. Updating the service reference worked.

2) The second issue was caused by a dependency issue. I updated the nuget package on both sides and everything appeared correct, but an unmarked dependency was out of sync. Example:

Package Foo v1 references Bar v1. It is possible to update Foo and Bar to v2 independently without updating the reference. If you install both Foo and Bar v2 the service reference tool will scan Foo v2, see the reference to Bar v1, and fail because it can't find the older version. This is only reported correctly if you update the version numbers of your dll for every package. Visual Studio and MSBuild will have no problem building the application but the service reference will have a terrible time trying to resolve everything.

I hope this helps someone.

Mean answered 15/1, 2016 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.