2

I have to build a .Net application that consumes a bunch of web service. This web service runs under weblogic. The WSDL of the web services mention a XSD file that describes the types.

When I try to add a "Service reference" with VS studio, I have some errors :

Warning 1 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter Error: Schema with target namespace 'http://mycustomer/ws/types' could not be found. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://mycustomer/ws/wsdl']/wsdl:portType[@name='lbWebPT'] C:\Projects\mycustomerproject\Service References\ClientService\Reference.svcmap

X3 for the portType, Binding and port elements of the wsdl file.

I was guessing this was because of the missing types defined in the xsd file. To workaround this error, and also to avoid duplicate code, I run the following command on my xsd file (in a pre-build event command line) :

"%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\bin\xsd.exe" "$(ProjectDir)xsdofmycustomer.xsd" /namespace:"MyCustomer.WebServices.Types" /c /o:"$(ProjectDir)."

this command successfully produces a code file with the types and with the correct namespace defined in the XmlRootAttribute.

this code has been put a dedicated VS project. The project where I'm trying to reference the service reference this project. However, the error is still occurring.

What can I do to solve my problem ?

PS: I was able to partially solve my problem using svcutil.exe pathtowsdl pathtoxsd, but I'd like to be able to maintain the reference in VS for ease of use.

thx

Steve B
  • 36,818
  • 21
  • 101
  • 174

1 Answers1

2

I'm not a fan of using project Service References because of the cruft the proxy generator inserts by default. But, if you really want to use Service References for your project then you need to merge the contents of the wsdl & xsd files into a single file. The Service Reference UI assumes all the data it needs to generate the proxy is in the file you give it. SvcUtil is more flexible as you found out. You should able to replace the wsdl:import element with a wsdl:types element that contains the xsd file contents (without the xml directive of course). Next, you enter the path to the file in the address textbox of the Add Service Reference dialog and you should be good to go with Visual Studio catered proxy goodness.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • it's an interesting point of view. My problem is that updating the service reference is one click in VS. Moving to a batch file the rebuild of the references is not as painful as it can appears... I'm just trying to make the code and project readable by other developers for the future evolutions. thx – Steve B Mar 31 '11 at 14:51
  • I favor ChannelFactory based client code where T is the interface marked with the ServiceContract attribute. SvcUtil based code will generate the ServiceContract marked interface and all the related DataContract marked classes for you. If you don't mind ignoring the SOA tenets, you can share the actual service contract assembly between the client & the service and use it for the T. A generic service invoker class we wrote handles making the service call and also takes care of faulted channel conditions when the service fails. – Sixto Saez Mar 31 '11 at 15:09
  • It isn't generally necessary to combine the WSDL and XSD files in order to use "Add Service Reference", though this may be necessary under some circumstances. – John Saunders Feb 14 '14 at 02:24
  • You're correct, the Add Service Reference will handle separate WSDL & XSDs automatically. In the context of this question however, it seems the way the external XSD document was being referenced didn't work for Steve. I "cut the Gordian knot" by recommending direct embedding of the XSDs instead of trying to crafting the correct reference to them. Thanks for noting WSDL & XSD docs aren't required to be combined for future answer readers! – Sixto Saez Feb 14 '14 at 15:46