Add Service Reference is generating Message Contracts
Asked Answered
D

5

17

When I import a given service using "Add service Reference" on Visual Studio 2008 (SP1) all the Request/Response messages are being unnecessarily wrapped into Message Contracts (named as --> "operationName" + "Request"/"Response" + "1" at the end).

The code generator says:

// CODEGEN: Generating message contract since the operation XXX is neither RPC nor 
// document wrapped.

The guys who are generating the wsdl from a Java service say they are specifying DOCUMENT-LITERAL/WRAPPED.

Any help/pointer/clue would be highly appreciated.

Update: this is a sample of my wsdl for one of the operations that look suspicious. Note the mismatch on the message element attribute for the request, compared to the response.

<!- imports namespaces and defines elements -->
<wsdl:types>
  <xsd:schema targetNamespace="http://WHATEVER/" xmlns:xsd_1="http://WHATEVER_1/" xmlns:xsd_2="http://WHATEVER_2/">
      <xsd:import namespace="http://WHATEVER_1/" schemaLocation="WHATEVER_1.xsd"/>
      <xsd:import namespace="http://WHATEVER_2/" schemaLocation="WHATEVER_2.xsd"/>
      <xsd:element name="myOperationResponse" type="xsd_1:MyOperationResponse"/>
      <xsd:element name="myOperation" type="xsd_1:MyOperationRequest"/>
   </xsd:schema>
</wsdl:types>

<!- declares messages - NOTE the mismatch on the request element attribute compared to response -->
<wsdl:message name="myOperationRequest">
   <wsdl:part element="tns:myOperation" name="request"/>
</wsdl:message>
<wsdl:message name="myOperationResponse">
   <wsdl:part element="tns:myOperationResponse" name="response"/>
</wsdl:message>

<!- operations -->
<wsdl:portType name="MyService">
   <wsdl:operation name="myOperation">
      <wsdl:input message="tns:myOperationRequest"/>
      <wsdl:output message="tns:myOperationResponse"/>
      <wsdl:fault message="tns:myOperationFault" name="myOperationFault"/>
      <wsdl:fault message="tns:myOperationFault1" name="myOperationFault1"/>
   </wsdl:operation>
</wsdl:portType>

Update 2: I pulled all the types that I had in my imported namespace (they were in a separate xsd) into the wsdl, as I suspected the import could be triggering the message contract generation. To my surprise it was not the case and having all the types defined in the wsdl did not change anything.

I then (out of desperation) started constructing wsdls from scratch and playing with the maxOccurs attributes of element attributes contained in a sequence attribute I was able to reproduce the undesired message contract generation behavior.

Here's a sample of an element:

<xsd:element name="myElement">
   <xsd:complexType>
      <xsd:sequence>
         <xsd:element minOccurs="0" maxOccurs="1" name="arg1" type="xsd:string"/>
      </xsd:sequence>
   </xsd:complexType>
</xsd:element>

Playing with maxOccurs on elements that are used as messages (all requests and responses basically) the following happens:

  • maxOccurs = "1" does not trigger the wrapping
  • macOcccurs > 1 triggers the wrapping
  • maxOccurs = "unbounded" triggers the wrapping

I was not able to reproduce this on my production wsdl yet because the nesting of the types goes very deep, and it's gonna take me time to inspect it thoroughly. In the meanwhile I am hoping it might ring a bell - any help highly appreciated.

Daune answered 3/3, 2010 at 22:19 Comment(1)
also note - that I am getting that error on all of the ioperations not only on a particular one. I seem to understand this could be due to an error on ANY of the type definitions used by ANY of the operations, this would cause the DataContractSerialer to be replaced by XmlSerializer, hence the MEssageContracts. Does this interpretation make any sense?Daune
I
5

I had this same issue and this solved it.

I used this:

    <wsdl:message name="Method">
      <wsdl:part name="parameters" element="s0:Method"/>
    </wsdl:message>

    <wsdl:message name="MethodResponse">
      <wsdl:part name="parameters" element="s0:MethodResponse"/>
    </wsdl:message>

Instead of:

    <wsdl:message name="Method">
      <wsdl:part name="request" element="s0:Method"/>
    </wsdl:message>

    <wsdl:message name="MethodResponse">
      <wsdl:part name="response" element="s0:MethodResponse"/>
    </wsdl:message>

I believe someone mentioned it before but I can't upVote their answer yet!

Inward answered 15/8, 2013 at 14:30 Comment(1)
Just to add my 5 cents: operation name should be exactly as message element name (Method as in the example above). Also response element should be exactly <operation name>Response (MethodResponse in the example above)Burnet
R
4

Here is another item to check:

  1. Right click on your service reference in the Solution Explorer and select 'Configure Service Reference'

  2. Check whether or not 'Always generate message contracts' is checked.

Rectify answered 12/3, 2010 at 5:9 Comment(1)
already went there - that box is not checked, but good suggestion! :)Daune
G
4

Have you tried changing the WSDL so that for every instance of part element="tns:myOperation" name="request", changing the value of the name attribute to 'parameters'.

Gurnard answered 1/11, 2012 at 16:17 Comment(0)
F
2

Did you try using the scvutil Goto --> Startmenu / Visual Studio 2008 / Tools / VS Command Prompt

Type svcutil, then check out the parameters, especially the /wrapped parameter. Eventually use this to generate your proxy, it gives you alot more control over whats going on

Ferne answered 4/3, 2010 at 13:11 Comment(1)
I did try with svcutil and got the same problem but did not play with the /wrapper parameter - will check that outDaune
C
2

While I know this is a long out dated entry, for those that stumble on this same issue:

Double check that the proxy that was generated doesn't contain any jagged arrays, e.g.

(C#)

private string[][] mystring;

(VB.NET)

Private myString()() As String
Corwin answered 7/4, 2011 at 20:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.