Error: Cannot import wsdl:port with svcutil

2019-07-27 10:28发布

问题:

I created a small WCF service (hosted in IIS) and used Chrome to take the wsdl of it, put that in a .wsdf file and then wanted to use svcutil test.wsdl to generate the client proxy out of it but I'm getting this error:

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

Anyone else encountered this and found a solution for it?

Update: as suggested by John Saunders, thanks for that, it works when I point it out directly to the url. However this is my little test case to see what svcutil can do as I expect the coming days to get a wsdl file from a 3rd party and might run into the same problem. As I took the most simplistic out of the box generated .svc I don't seem to be having include blocks.

回答1:

If the wsdl has Include blocks in it - and they often do when generated by WCF - then you're likely only saving the 'main' wsdl file and not all the referenced files.

The result of this is that the main file won't make any sense. As John Saunders suggests, try giving the URL to svcutil.exe instead of saving the file.