Fault Contract support issue

Jun 28, 2010 at 11:11 PM

I'm having a problem with the Fault Contract support. I think I am missing something but here goes.

I am starting with this schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema
  xmlns:user="http://schemas.acme.com/Core/User/v1.0"
  xmlns="http://schemas.acme.com/Core/UserServiceMessages/v1.0"
  elementFormDefault="qualified"
  targetNamespace="http://schemas.acme.com/Core/UserServiceMessages/v1.0"
  id="UserServiceMessages"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import
    schemaLocation=".\User-v1.0.xsd"
    namespace="http://schemas.acme.com/Core/User/v1.0" />
  <xs:element name="FindRequest">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="1" name="username" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="FindResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="1" ref="user:User" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="UserNotFoundFault">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="UserName" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Which gives this WSDL (I choose to add a fault contract during the wizard):

<!--WSDL generated by thinktecture WSCF; version 1.0.9.0-->
<!--Tuesday, 29-06-2010 - 12:02 AM-->
<definitions xmlns:tns="http://schemas.acme.com/Core/UserService/v1.0" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:import0="http://schemas.acme.com/Core/UserServiceMessages/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="UserService" targetNamespace="http://schemas.acme.com/Core/UserService/v1.0" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <types>
    <xsd:schema>
      <xsd:import schemaLocation="UserServiceMessages-v1.0.xsd" namespace="http://schemas.acme.com/Core/UserServiceMessages/v1.0" />
    </xsd:schema>
  </types>
  <message name="findIn">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="import0:FindRequest" />
  </message>
  <message name="findOut">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="import0:FindResponse" />
  </message>
  <message name="UserNotFoundFaultMessage">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="fault" element="import0:UserNotFoundFault" />
  </message>
  <portType name="UserServiceInterface">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <operation name="Find">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
      <input message="tns:findIn" />
      <output message="tns:findOut" />
      <fault name="UserNotFoundFaultMessage" message="tns:UserNotFoundFaultMessage" />
    </operation>
  </portType>
  <binding name="BasicHttpBinding_UserServiceInterface" type="tns:UserServiceInterface">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="Find">
      <soap:operation soapAction="http://schemas.acme.com/Core/UserService/v1.0:findIn" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
      <fault name="UserNotFoundFaultMessage">
        <soap:fault use="literal" name="UserNotFoundFaultMessage" namespace="" />
      </fault>
    </operation>
  </binding>
  <service name="UserServicePort">
    <port name="UserServicePort" binding="tns:BasicHttpBinding_UserServiceInterface">
      <soap:address location="http://localhost/UserService" />
    </port>
  </service>
</definitions>

But I get the following error in the Visual Studio output window:

Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: The datatype 'http://schemas.acme.com/Core/UserServiceMessages/v1.0:UserNotFoundFault' is missing.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.acme.com/Core/UserService/v1.0']/wsdl:portType[@name='UserServiceInterface']
---------------------------------------------------------------------------------
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://schemas.acme.com/Core/UserService/v1.0']/wsdl:portType[@name='UserServiceInterface']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.acme.com/Core/UserService/v1.0']/wsdl:binding[@name='BasicHttpBinding_UserServiceInterface']
---------------------------------------------------------------------------------
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://schemas.acme.com/Core/UserService/v1.0']/wsdl:binding[@name='BasicHttpBinding_UserServiceInterface']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://schemas.acme.com/Core/UserService/v1.0']/wsdl:service[@name='UserServicePort']/wsdl:port[@name='UserServicePort']
---------------------------------------------------------------------------------

Any ideas?

Thanks,

Callum

Developer
Jun 29, 2010 at 11:50 AM

Hi Callum,

I am glad to hear that you are using the new fault contract support. Try defining your fault type explicitly:

<xs:element name="UserNotFoundFault" type="UserNotFoundFault" />
<xs:complexType name="UserNotFoundFault">
  <xs:sequence>
    <xs:element name="UserName" type="xs:string" />
  </xs:sequence>
</xs:complexType>

That should do the trick.

Cheers,

Alex.

Jul 2, 2010 at 10:17 AM

This did work for me, just letting you know that originally I was following the instructions here: http://alexmg.com/post/2010/05/31/Fault-Contract-support-in-WSCFblue.aspx

I didn't find it obvious from that post I needed to seperate the fault into a seperate type, it might be worth updating the text or highlighting the point.

The error message does make sense to me now I know what I did wrong but my brain did not click at the time.

Thanks. This is a great tool.

Callum

Developer
Jul 2, 2010 at 1:06 PM

Hi Callum,

Thanks for reporting back. I have updated my blog post to include a sample fault type and message, as well as to point out that you should not declare your fault type as an anonymous type definition directly under the message element.

Cheers,

Alex.