Add Service Reference is generating Message Contracts - wcf

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.

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!

Here is another item to check:
Right click on your service reference in the Solution Explorer and select 'Configure Service Reference'
Check whether or not 'Always generate message contracts' is checked.

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'.

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

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

Related

request generation in vb.net soap client

Take the tripservice wsdl from this link In this wsdl, I replaced the from element with the below(added nillable as true and added min length and max length restriction).
<xs:element minOccurs="0" name="from" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Now in my vb.net client i invoked the service by adding service reference, wsdl saved to a local folder.
Dim objproxy As New Tripservice.TripPriceServiceFacadeClient
Dim gh As New Tripservice.trip
gh.adults = 9
gh.duration = 8
gh.rooms = 8
gh.to = "p"
objproxy.getTripPrice(gh)
It will throw end point not found exception, however i am interested in the request xml that is going. I enabled the trace and found that the below request is generated.
<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">
<getTripPrice xmlns="http://trip.price.service">
<trip xmlns="">
<adults>9</adults>
<duration>8</duration>
<from xsi:nil="true"/>
<rooms>8</rooms>
<to>p</to>
</trip>
</getTripPrice>
</s:Body>
</s:Envelope>
The element from xsi:nil="true" is generated, even though i am not touching the element in my vb.net code to generate the request. The element is optional as per the wsdl(min occurs = 0). How can i send a request without the from element name, even passed in the request?
You can't; it is interesting to find out why you changed it to nillable; in doing that, the way .NET code generation works, you leave it no way to know whether it should marshall the tag or not; typically, an optional string that is null is not marshalled. An optional (minOccurs=0) and nillable wouldn't work since there is no "set" indicator (JAXB has it or use to have it) to keep trace whether the user code set the value, null or not null.

WCF WSDL Generation Details on How and what each section means

I'm quiet new to WCF world.
I've been looking and trying to understand the WSDL file being generated by WCF. the reason I'm looking is that our clients with Java and PHP are having issue importing the WSDL.
Could anyone please kindly help me with following queries:
- <xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:13818/WCFService2/Service.svc?xsd=xsd0" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="http://localhost:13818/WCFService2/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:import schemaLocation="http://localhost:13818/WCFService2/Service.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/EvalServiceLibrary" />
</xsd:schema>
Query 1
Based on what condition is above import schemalocation tags gets generated? Is it based on number of data contracts and members or somethingelse (what is it?)
- <wsdl:message name="IEvalService_SubmitEval_InputMessage">
<wsdl:part name="parameters" element="tns:SubmitEval" />
</wsdl:message>
- <wsdl:message name="IEvalService_SubmitEval_OutputMessage">
<wsdl:part name="parameters" element="tns:SubmitEvalResponse" />
</wsdl:message>
Query 2:
I don't have any message name IEvalService_SubmitEval_InputMessage. How is above being generated? Also what is part name and element?
<wsdl:portType name="IEvalService">
- <wsdl:operation name="SubmitEval">
<wsdl:input wsaw:Action="http://tempuri.org/IEvalService/SubmitEval" message="tns:IEvalService_SubmitEval_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/IEvalService/SubmitEvalResponse" message="tns:IEvalService_SubmitEval_OutputMessage" />
</wsdl:operation>
</wsdl:portType>
Query 3:
could yo uplease tell me what is "tns:IEvalService_SubmitEval_InputMessage" on above wsdl snippet?
Fianally:
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org
/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org
/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
is thre any way to remove the above unnecessary namespace from WCF code? I only know how to change the namespace.
Thank you heaps.
This part depends on number of assemblies involved. The first line represents your service assembly, second line is always included - that some MS predefined elements (but still valid interoperable XSD) and the third line is probably library with your data contracts.
The default pattern is ServiceContractName_OperationContractName_X where X is either InputMessage or OutputMessage to differ between request and response. Part defines content of the message and element is reference to XSD scheme - that element will be defined in first or second schema import from your first question.
tns probably stands for target namespace - it is a prefix of elements defined in your WSDL document. It is just reference to message defined in your second question.
With default stuff no. You would probably need custom encoder.
What errors do your clients have when importing the WSDL? All these parts are valid.

Sending Complex Objects, Attachments with ksoap2-Android

I'm using ksoap2-Android on an Android project to upload a file. It's not working.
First of all, my wsdl looks like this:
<xsd:element name="Op1RequestType">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="date" type="xsd:dateTime"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="imgFile"
type="tns:Attachment"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
And "tns:Attachment" is defined like this:
<xsd:complexType name="Attachment">
<xsd:sequence>
<xsd:element name="file" type="xsd:base64Binary"/>
<xsd:element name="filename" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
I'm creating a SoapSerializationEnvelope and adding in the property with name date and the value as the string representation of the current date. This works successfully, even if I don't add a file (note the minOccurs="0"). However, when I try to add a file, it fails horribly:
First, I make a representative of the Attachment type by creating a SoapObject which has the properties file and filename, of types byte[].class and String.class respectively.
Then I add these objects to a generic Vector (to represent the multiplicity of the imgFile item) and attach the Vector as a property to the envelope. This creates a SOAP message successfully, and the response from the server raises an exception (because it's an error message, instead of a proper response, because somehow my input isn't good...):
WARN/System.err(438): SoapFault - faultcode: 'soapenv:Server'
faultstring:'org.apache.axis2.databinding.ADBException: Unexpected subelement imgFile'
faultactor: 'null' detail: org.kxml2.kdom.Node#4676b8a0
Okay, so what am I doing wrong? Is there a way to see the request SOAP envelope that I am sending?
I can see the request SOAP envelope by calling getRequest() on the SoapSerializationEnvelope. This allowed me to see that the vector object actually places each (file, filename) pair into an <item></item> tag, which broke the format. I now am inserting multiple items in succession as the wsdl demands.

WSDL with type int or blank is not readable by stubs generated by wsdl2java

I have created a simple type
<xsd:simpleType name="IntOrBlank">
<xsd:union memberTypes="xsd:int">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value=""/>
</xsd:restriction>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>
I then create stubs using wsdl2java from axis2, the sending works and receiving seemed to work until I try to obtain the integer value from this type. My code is as such:
IntOrBlank get_part_custom_field7 = each_record[0].get_part_custom_field7();
Object object = get_part_custom_field7.getObject();
The object is null now. eventhough the SOAP message is coming in as
<bm:_part_custom_field7>9</bm:_part_custom_field7>
I trace through the code and I found that wsdl2java has generated the stubs incorrectly. The object that was created was java.math.BigInteger while the stubs did a check to make sure the object is an instance of Integer, as a result, the object is null without throwing any exception. I changed the type to
<xsd:simpleType name="IntOrBlank">
<xsd:union memberTypes="xsd:integer">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value=""/>
</xsd:restriction>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>
and solved the problem
I'd suggest you stop using union that way, maybe not at all.
You've just found one tool that doesn't deal with it the way you'd like - there will be many others. union doesn't really make much sense in this context. What Java type should be used in this case? Object?
What about in this case:
<xs:simpleType name="SillyUnion">
<xs:union memberTypes="xs:int xs:string"/>
</xs:simpleType>
What data type would you have wsdl2java use for this? Object again? How would a programmer consuming this data determine whether integer or string data had been included? Do you really mean that everyone using this data should check first?
Union is one of those things that sounded like a good idea at the time, and which has turned out not to be as helpful as was previously thought.

asmx wsdl string length

I have a VB class in an .asmx file in Visual Studio 2008:
public class foo
public bla as String
end class
It generates the wsdl value:
<s:complexType name="foo">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="bla" type="s:string" />
</s:sequence>
</s:complexType>
But what I want the wsdl to generate is:
<xs:element name="bla" type="xs:string"
sql:datatype="varchar(25)" minOccurs="1" maxOccurs="1">
</xs:element>
Is there a way to do this?
Or can I edit the generated WSDL?
You can use The System.Xml.Serialization.XmlElementAttribute to mark the property IE:
<XmlElement(DataType := "varchar(25)")>
(my vb is a little rusty if this isn't correct
syntax)
You can save off the WSDL and edit it, however, if you change the WSDL, a proxy generated from it may not be able to communicate with your service.
Edit: If you have the target schema, I would suggest that you use xsd.exe or wsdl.exe to generate the classes you need to serialize to valid documents according to that schema.