Include Schema Type in WSDL file
Asked Answered
B

3

9

I created a WSDL by hand that has only one operation with no input parameter and no output parameter.

I am getting following error when I try to create a client from this WSDL:

Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Schema with target namespace 'http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/' could not be found. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/']/wsdl:portType[@name='GAMEAssociateIntf'] C:\toolbox\BlueTest\BloodRedTest\BloodRedTest\Service

The types (to be used in the client) need to be generated from the XML present in the WSDL. I think, while adding Service Reference, the tool is failing to create it due to some error in the XML. The xsd seems to be the issue.

What change need to be done in the WSDL to create the proxy ?

Note: I am trying to include the xml types defined in WSDL itself. [I don't need a separate file for schema defenition]

WSDL

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GAMEAssociate" 
         targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
         xmlns:tns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
         xmlns="http://schemas.xmlsoap.org/wsdl/" 
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
         xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:wsp="http://www.w3.org/ns/ws-policy"
         >

<types>
<xsd:schema>
</xsd:schema>

<xsd:element name="myData">
  <xsd:complexType />
</xsd:element>

<xsd:element name="myDataResponse">
  <xsd:complexType />
</xsd:element>

</types>

<message name="getAllVicePresidentsRequest">
<part element="tns:myData" name="getAllVicePresidentsRequest"/>
</message>

<message name="getAllVicePresidentsResponse">
<part element="tns:myDataResponse" name="getAllVicePresidentsResponse"/>
</message>

<portType name="GAMEAssociateIntf">
<operation name="getAllVicePresidents">
  <input message="tns:getAllVicePresidentsRequest"/>
  <output message="tns:getAllVicePresidentsResponse"/>
</operation>
</portType>

<binding name="GAMEAssociateIntfBinding" type="tns:GAMEAssociateIntf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<operation name="getAllVicePresidents">
  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"
                  style="document"/>
  <input>
    <soap:body use="literal"/>
  </input>
  <output>
    <soap:body use="literal"/>
  </output>

</operation>

</binding>

<service name="GAMEAssociate">
<port binding="tns:GAMEAssociateIntfBinding" name="GAMEAssociateSOAP">
  <soap:address location="http://localhost:8014/associateservice/GAMEAssociate.svc"/>
</port>
</service>

</definitions>

REFERENCES:

  1. WSDL - no input - best practice
  2. What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType"
  3. Writing a WSDL 1.1 Web Service Contract by Hand
  4. Writing Contract-First Web Services
  5. generate wcf server code from wsdl files
  6. How to get wsdl input and output names to appear
  7. Inline Schema
  8. Hand rolled SOAP request
Basicity answered 4/4, 2013 at 15:11 Comment(5)
You said no input parameter and no output parameter. But, I can see your operation is defining an input and an output parameter.Jacquijacquie
@Indoknight These messages are empty. I think, we need such messages as explained in https://mcmap.net/q/947217/-wsdl-no-input-best-practiceBasicity
I haven't worked on C#, but WSDL looks alright. I checked in SOAPUI.Jacquijacquie
@Indoknight Thanks. Are you able to create a service AND client in any programming language using this WSDL? Is the operation giving proper response?Basicity
Reference: Inline schemasBasicity
B
1

I referred Inline Schema. Thanks to @Indoknight also. The working contract WSDL is given below.

Note1: The xsd prefix and targetNamespace is there in the schema that is used inside wsdl type

Note2: nillable="true" is applied for the type used in the response message

Note3: If you are getting following exception, make sure that the soapAction is exactly same in the contract WSDL and the wsdl generated from WCF service. Some tools used for generating Service code may modify the SOAP action at it’s own will.

Faultcod: a:ActionNotSupported

Faultstring: The message with Action 'http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

SOAP Action - Contract WSDL

  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"

SOAP Action - Generated WSDL

<soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/IGAMEAssociateIntf/getAllVicePresidents"

Contract WSDL

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GAMEAssociate"
     targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
     xmlns:tns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
     xmlns="http://schemas.xmlsoap.org/wsdl/"
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:wsp="http://www.w3.org/ns/ws-policy"
     >

<types>
<xsd:schema targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
  <xsd:element name="myData">
    <xsd:complexType />
  </xsd:element>
  <xsd:element name="myDataResponse" nillable="true">
    <xsd:complexType />
  </xsd:element>
</xsd:schema>
</types>

<message name="getAllVicePresidentsRequest">
<part element="tns:myData" name="getAllVicePresidentsRequest"/>
</message>

<message name="getAllVicePresidentsResponse">
<part element="tns:myDataResponse" name="getAllVicePresidentsResponse"/>
</message>

<portType name="GAMEAssociateIntf">
<operation name="getAllVicePresidents">
  <input message="tns:getAllVicePresidentsRequest"/>
  <output message="tns:getAllVicePresidentsResponse"/>
</operation>
</portType>

<binding name="GAMEAssociateIntfBinding" type="tns:GAMEAssociateIntf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getAllVicePresidents">
  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"
                  style="document"/>
  <input>
    <soap:body use="literal"/>
  </input>
  <output>
    <soap:body use="literal"/>
  </output>
</operation>
</binding>

<service name="GAMEAssociate">
<port binding="tns:GAMEAssociateIntfBinding" name="GAMEAssociateSOAP">
  <soap:address location="http://localhost:8014/associateservice/GAMEAssociate.svc"/>
</port>
</service>

</definitions>

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">
<soapenv:Header/>
<soapenv:Body>
  <ns:myData/>
</soapenv:Body>
</soapenv:Envelope>

Response

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>
</s:Body>
</s:Envelope>
Basicity answered 26/4, 2013 at 17:21 Comment(1)
the "inline schema" link seems broken.Jus
J
6

I spent some time trying to find out issues. Your <types> section of the wsdl is incorrect, it should be like below. With this, I can now generate client side artefacts in Java.

<types>
<schema targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
          xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="myData">
     <complexType/> 
   </element>

   <element name="myDataResponse">
     <complexType/>
   </element>
</schema></types>

UPDATE

Based on the conversation below. Added a nillable attribute.

<element name="myDataResponse" nillable="true">
<complexType/>
</element>

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">
<soapenv:Header/>
<soapenv:Body>
  <ns:myData/>
</soapenv:Body>
</soapenv:Envelope>

Response

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>
</s:Body>
</s:Envelope>
Jacquijacquie answered 19/4, 2013 at 17:15 Comment(10)
Thanks. When I tried it with SOAP UI, the myDataResponse is not appearing in the response whereas myData is present in input. Any idea why?Basicity
I created SOAPUI project with the modified wsdl and also created a mock service. Then I got this response <soapenv:Envelope xmlns:soapenv="schemas.xmlsoap.org/soap/envelope" xmlns:ns="xmlns.mycompany.com/GAME/service/Associate/1.1"> <soapenv:Header/> <soapenv:Body> <ns:myDataResponse/> </soapenv:Body> </soapenv:Envelope>Jacquijacquie
Are you firing your request on actual web service? If so, what output you are seeing?Jacquijacquie
I created a WCF service from this WSDL. I tested with SOAP UI (by using the WSDL generated by WCF). Following is the response with no myDataResponse - <s:Envelope xmlns:s="schemas.xmlsoap.org/soap/envelope"> <s:Body xmlns:xsi="w3.org/2001/XMLSchema-instance" xmlns:xsd="w3.org/2001/XMLSchema"> </s:Envelope>Basicity
@Lijo I guess you are creating your web service and then generating WSDL out of it, which is a bottom-up web service creation. I'd recommend using top-down approach which means creating your webservice from the modified WSDL. Not sure if this helps but you can give a try.Jacquijacquie
I found out... Including nillable = "true" to the myDataResponse element resolved the problem.Basicity
Great! But, the default value of nillable false should naturally make the element mandatorily coming through. It seems you have results the other way round!!Jacquijacquie
Still, it is not working when I created SOAP UI project with contract WSDL and requested the WCF service. It says a contract mismatch.Basicity
I guess it is because there isn't any return from the service interface method. This wsdl should be as same as not having output element. The input element is on the otherhand needed to point to the right service interface method because the message is of document type.Jacquijacquie
We need to make sure that the soapAction is exactly same in the contract WSDL and the wsdl generated from WCF service.Basicity
L
1

wsi.org has a set of validation tools, which would certainly be worth trying.

The added benefit of using these tools is that you can then actually claim compliance with the WSDL specification(s).

Langlois answered 26/4, 2013 at 13:14 Comment(0)
B
1

I referred Inline Schema. Thanks to @Indoknight also. The working contract WSDL is given below.

Note1: The xsd prefix and targetNamespace is there in the schema that is used inside wsdl type

Note2: nillable="true" is applied for the type used in the response message

Note3: If you are getting following exception, make sure that the soapAction is exactly same in the contract WSDL and the wsdl generated from WCF service. Some tools used for generating Service code may modify the SOAP action at it’s own will.

Faultcod: a:ActionNotSupported

Faultstring: The message with Action 'http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

SOAP Action - Contract WSDL

  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"

SOAP Action - Generated WSDL

<soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/IGAMEAssociateIntf/getAllVicePresidents"

Contract WSDL

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GAMEAssociate"
     targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
     xmlns:tns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
     xmlns="http://schemas.xmlsoap.org/wsdl/"
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:wsp="http://www.w3.org/ns/ws-policy"
     >

<types>
<xsd:schema targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
  <xsd:element name="myData">
    <xsd:complexType />
  </xsd:element>
  <xsd:element name="myDataResponse" nillable="true">
    <xsd:complexType />
  </xsd:element>
</xsd:schema>
</types>

<message name="getAllVicePresidentsRequest">
<part element="tns:myData" name="getAllVicePresidentsRequest"/>
</message>

<message name="getAllVicePresidentsResponse">
<part element="tns:myDataResponse" name="getAllVicePresidentsResponse"/>
</message>

<portType name="GAMEAssociateIntf">
<operation name="getAllVicePresidents">
  <input message="tns:getAllVicePresidentsRequest"/>
  <output message="tns:getAllVicePresidentsResponse"/>
</operation>
</portType>

<binding name="GAMEAssociateIntfBinding" type="tns:GAMEAssociateIntf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getAllVicePresidents">
  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"
                  style="document"/>
  <input>
    <soap:body use="literal"/>
  </input>
  <output>
    <soap:body use="literal"/>
  </output>
</operation>
</binding>

<service name="GAMEAssociate">
<port binding="tns:GAMEAssociateIntfBinding" name="GAMEAssociateSOAP">
  <soap:address location="http://localhost:8014/associateservice/GAMEAssociate.svc"/>
</port>
</service>

</definitions>

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">
<soapenv:Header/>
<soapenv:Body>
  <ns:myData/>
</soapenv:Body>
</soapenv:Envelope>

Response

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>
</s:Body>
</s:Envelope>
Basicity answered 26/4, 2013 at 17:21 Comment(1)
the "inline schema" link seems broken.Jus

© 2022 - 2024 — McMap. All rights reserved.