Include Schema Type in WSDL file - wcf

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:
WSDL - no input - best practice
What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType"
Writing a WSDL 1.1 Web Service Contract by Hand
Writing Contract-First Web Services
generate wcf server code from wsdl files
How to get wsdl input and output names to appear
Inline Schema
Hand rolled SOAP request

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>

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

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>

Related

WSO2 ESB 4.9 Call mediator is not working fine in same situations

I have a proxy service with below definition:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<header name="Action" value="urn:loadPerson"/>
<payloadFactory media-type="xml">
<format>
<sear:loadPerson xmlns:sear="http://localhost/SearchService">
<sear:Id>1234</sear:Id>
</sear:loadPerson>
</format>
<args/>
</payloadFactory>
<log level="full"/>
<call>
<endpoint key="SearchService"/>
</call>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
So it's work fine when I call the proxy service(by tryIt) first time and I get right response of proxy service but for the next time it faces a problem and show me fault response:
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>axis2ns11:Server</faultcode>
<faultstring>Missing operation for soapAction [urn:loadPerson] and body element [null] with SOAP Version [SOAP 1.1]</faultstring>
</soapenv:Fault>
As you can see I log the message and it's the same for every proxy call:
INFO - LogMediator To: /services/TestProxy.TestProxyHttpSoap11Endpoint, WSAction: urn:loadPerson, SOAPAction: urn:loadPerson, MessageID: urn:uuid:cc9557cc-e2a0-4b8d-97a8-ae393a411157, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><sear:loadPerson xmlns:sear="http://localhost/SearchService"><sear:Id>1234</sear:Id></sear:loadPerson></soapenv:Body></soapenv:Envelope>
I found that the problem resolved by restarting the server(not redeploying the proxy service) or leave it for few minutes!
any idea?!

WCF Method with parameter not generating right WSDL

I have a simple service definition:
[ServiceContract]
public interface IInterface12
{
[OperationContract]
void SendInterface12(string appId);
}
which I have implemented in the service as:
public void SendInterface12(string appId)
{
The thing is that the string parameter appId is not showing up. The complete WSDL is here:
<?xml version="1.0" encoding="UTF-8"?>
-<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/" name="Interface12Service">
-<wsdl:types>
-<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import namespace="http://tempuri.org/" schemaLocation="http://localhost/TestInterface12/Interface12Service.svc?xsd=xsd0"/>
<xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="http://localhost/TestInterface12/Interface12Service.svc?xsd=xsd1"/>
</xsd:schema>
</wsdl:types>
-<wsdl:message name="IInterface12_SendInterface12_InputMessage">
<wsdl:part name="parameters" element="tns:SendInterface12"/>
</wsdl:message>
-<wsdl:message name="IInterface12_SendInterface12_OutputMessage">
<wsdl:part name="parameters" element="tns:SendInterface12Response"/>
</wsdl:message>
-<wsdl:portType name="IInterface12">
-<wsdl:operation name="SendInterface12">
<wsdl:input message="tns:IInterface12_SendInterface12_InputMessage" wsaw:Action="http://tempuri.org/IInterface12/SendInterface12"/>
<wsdl:output message="tns:IInterface12_SendInterface12_OutputMessage" wsaw:Action="http://tempuri.org/IInterface12/SendInterface12Response"/>
</wsdl:operation>
</wsdl:portType>
-<wsdl:binding name="BasicHttpBinding_IInterface12" type="tns:IInterface12">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
-<wsdl:operation name="SendInterface12">
<soap:operation style="document" soapAction="http://tempuri.org/IInterface12/SendInterface12"/>
-<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
-<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
-<wsdl:service name="Interface12Service">
-<wsdl:port name="BasicHttpBinding_IInterface12" binding="tns:BasicHttpBinding_IInterface12">
<soap:address location="http://localhost/TestInterface12/Interface12Service.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
What am I missing? I have to have a service operation that takes a parameter but when I generate the proxy, there is no parameter for the string appId parameter. It says it takes 0 parameters.
Most probably the WSDL references an XSD file where your parameter is defined. Search for "import" or "include" to see the location of that XSD. If this is your wsdl location: http://myserver.com/X.svc?WSDL=WSDL0 then the XSD is in http://myserver.com/x.svc?XSD=XSD0 (or XSD1, XSD2...). Possibly your WSDL references another WSDL (WSDL1) which is the one that references the XSD (or a few of them).

wsdl has unresolved urls. Service proxy returns null

I am trying to connect to an external webservice and have no control over it.
The wsdl has a few unresolved urls. Neither Soap UI not svcutil were able to make any use out of it.
So I browsed to this wsdl and did a 'Save As' to a xml document. Then I went and manually changed it these few to the correct one.
For eg:
https://b2borexatest.oracleoutsourcing.com/soa-infra/services/default/MMISSOAPRequestReceiver!1.0*soa_d48cf4e0-5e7b-43ad-b430-727180d48841/RouteEDITransactions_ep?WSDL. T
This was the original webservice Wsdl given. and then they changed it to
https://orserviceb2btest.oracleoutsourcing.com/soa-infra/services/default/MMISSOAPRequestReceiver!1.0/CORERule220.wsdl
I am able to browse to the second url but it still contains some traces of the old one 'b2b....'
So I went and manually changed these traces to reflect to the correct one.
By doing so, I was able to create a proxy using svcutil.
Question: Could this be the possible reason for getting a webservice proxy returns null
SOAP UI request
<soapenv:Envelope xmlns:cor="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<cor:COREEnvelopeRealTimeRequest>
<PayloadType>123</PayloadType>
<ProcessingMode>XXX</ProcessingMode>
<PayloadID>72</PayloadID>
<TimeStamp>2013-07-13:T23:30:29:45</TimeStamp>
<SenderID>MID</SenderID>
<ReceiverID>OID</ReceiverID>
<CORERuleVersion>2.2.0</CORERuleVersion>
<Payload>MY Input string</Payload>
</cor:COREEnvelopeRealTimeRequest>
</soapenv:Body>
This is the working SOAP UI response
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Body>
<COREEnvelopeRealTimeResponse xmlns:cor="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd" xmlns="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd">
<cor:PayloadType>XXX</cor:PayloadType>
<cor:ProcessingMode>23</cor:ProcessingMode>
<cor:PayloadID>372</cor:PayloadID>
<cor:TimeStamp>2013-08-04T23:38:32.083-05:00</cor:TimeStamp>
<cor:SenderID>OID</cor:SenderID>
<cor:ReceiverID>RID</cor:ReceiverID>
<cor:CORERuleVersion>2.2.0</cor:CORERuleVersion>
<cor:Payload>Response String</cor:Payload>
<cor:ErrorCode>Success</cor:ErrorCode>
<cor:ErrorMessage></cor:ErrorMessage>
</COREEnvelopeRealTimeResponse>
</env:Body>
I don't see any conflictions in the request/response
These are some relevant pieces of the wsdl
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions xmlns:CORE="http://www.caqh.org/SOAP/WSDL/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:CORE-XSD="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd" xmlns="http://schemas.xmlsoap.org/wsdl/" name="CORE" targetNamespace="http://www.caqh.org/SOAP/WSDL/">
<wsdl:types>
<xsd:schema xmlns="http://schemas.xmlsoap.org/wsdl/" elementFormDefault="qualified" targetNamespace="http://www.caqh.org/SOAP/WSDL/">
<xsd:import namespace="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd" schemaLocation="xsd/CORERule2.2.0.xsd"></xsd:import>
</xsd:schema>
</wsdl:types>
<wsdl:message name="RealTimeRequestMessage">
<wsdl:part name="body" element="CORE-XSD:COREEnvelopeRealTimeRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="RealTimeResponseMessage">
<wsdl:part name="body" element="CORE-XSD:COREEnvelopeRealTimeResponse"></wsdl:part>
</wsdl:message>
<wsdl:portType name="CORETransactions">
<wsdl:operation name="RealTimeTransaction">
<wsdl:input message="CORE:RealTimeRequestMessage"></wsdl:input>
<wsdl:output message="CORE:RealTimeResponseMessage"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CoreSoapBinding" type="CORE:CORETransactions">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"></soap12:binding>
<wsdl:operation name="RealTimeTransaction">
<soap12:operation soapAction="RealTimeTransaction" style="document"></soap12:operation>
<wsdl:input>
<soap12:body use="literal"></soap12:body>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"></soap12:body>
</wsdl:output>
</wsdl:operation>
I don't see where the proxy class could loose it although Fiddler captures the correct response.
This is a piece of where I invoke the service method using proxy client class
var ORrealTimeTrans = new COREEnvelopeRealTimeRequest()
{
PayloadType = "blabla",
ProcessingMode = bla,
PayloadID = bla,
CORERuleVersion = bla,
SenderID = sid,
ReceiverID = rid,
TimeStamp = DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:22Z"),
Payload = input
};
_ORclient.ClientCredentials.UserName.UserName = UserID;
_ORclient.ClientCredentials.UserName.Password = Password;
var resp = _ORclient.RealTimeTransaction(ORrealTimeTrans);
THis one _ORclient.RealTimeTransaction(ORrealTimeTrans) comes out null.
Could it be possible that I've changed some occurences of b2b to orservice and this proxy returns null?
Please suggest

How to generate a java web service class to a WSDL-file that works with sudzc.com to create objective-C code?

How can I generate from a Java Web Service class a WSDL-file, which is supported by Sudzc.com to generate a Objective-C code?
I tried it with a simple example.
My Java Web Service class:
package main;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
#WebService(name="RectangleWebService", serviceName = "RectangleWebService", portName = "RectangleWebServicePort", targetNamespace = "http://www.mywstest.com/ws/rectangle")
public class RectangleService {
#WebMethod(action="calculateValueOne")
public #WebResult(name="ValueOne") float calculateValueOne(#WebParam(name="Length") float length, #WebParam(name="Width")float width){
return 2*(length+width);
}
#WebMethod(action="calculateValueTwo")
public #WebResult(name="ValueTwo") float calculateValueTwo(#WebParam(name="Length") float length, #WebParam(name="Width")float width){
return (length*width);
}
}
I create a WSDL-file with an ant-script and wsgen and then I uploaded it on http://sudzc.com to create the Objective-C code (Objective-C for iOS with ARC). My Problem is that the created Objective-C code from Sudzc.com has no instance Methods...
This is my WSDL-file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. -->
<definitions targetNamespace="http://www.mywstest.com" name="RectangleWebService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.mywstest.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<import namespace="http://www.mywstest.com/ws/rectangle" location="RectangleWebServicePortType.wsdl"/>
<binding name="RectangleWebServicePortBinding" type="ns1:RectangleWebService" xmlns:ns1="http://www.mywstest.com/ws/rectangle">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="calculateValueOne">
<soap:operation soapAction="calculateValueOne"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="calculateValueTwo">
<soap:operation soapAction="calculateValueTwo"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="RectangleWebService">
<port name="RectangleWebServicePort" binding="tns:RectangleWebServicePortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
When I use the WSDL-file from http://www.w3schools.com/webservices/tempconvert.asmx?WSDL to generate the Objective-C code with sudzc.com, it works fine and I can use the instance methods
of the web service in my Objective-C project... !!!
Perhaps someone can help?
P.S. Sorry for my bad english and I am an absolute beginner in web services...
That sudzC has a lot of issues with memory, I use WSClient++ to generate the classes and never had a problem.
http://wsclient.neurospeech.com/
The problem is that the generated RectangleWebService.wsdl file has a schema import from an external schema1.xsd file...
So i have to create one wsdl-file and then it should work with sudzc.com...
Is my guess right?

Why does the XmlRoot attribute gets ignored in WCF and how to overcome this

We've observed that when we expose a WCF service which uses classes decorated with various xml serialisation attributes, despite the fact that we use the XmlSerializerFormat attribute on the interface any XmlRoot attribute on any of the operation's parameters gets completely ignored.
The namespace of the parameters is always that of the service and not what we specify.
This is causing us problems as it does not seem to be backwards compatible with ASMX and also because we're using BizTalk, and need to have tighter control over the shape of the XML's exchanged.
A few questions then -
Anybody knows what is the rationale
behind this decision?
Anybody knows
how this is happening? I was under
the impressions that WCF, with the
XmlSerializerFormat attribute, uses
the XmlSerialiser to serialise the
types, which would suggest XmlRoot
should be taken into account, how
come this is not the case? (is it
only due to the fact that, taking
the SOAP envelope into account, the
parameter is not root?)
Most
importantly - anybody knows if
there's a way to 'force the issue' -
i.e. get the parameters to be of the
namespace of our choosing?
I've seen this post, but I don't believe it is relevant to my question -
As per Wagner Silveira's request - the contracts I used to test this are -
[ServiceContract(Namespace = "http://servicecontract"),
XmlSerializerFormat(Style = OperationFormatStyle.Document)]
public interface ITestService
{
[OperationContract]
MyOtherType MyTestMethod(MyType obj);
}
// Composite class for DCS and XMLS
[Serializable, XmlType, XmlRoot(Namespace = "http://datacontract")]
public class MyType
{
[XmlAttribute]
public string StringValue { get; set; }
}
// Composite class for DCS and XMLS
[Serializable, XmlType, XmlRoot(Namespace = "http://datacontract")]
public class MyOtherType
{
[XmlAttribute]
public string OtherStringValue { get; set; }
}
I assume you're using SOAP as the message format. In this case, the object you're serializing is not the root of the XML, the soap envelope is. So it makes sense that the XmlRoot would be ignored. By default WCF will create a message contract for you and name the response and it has the namespace of the service. What you can do is create your own message contract to have full control over SOAP.
Create the following two classes:
[MessageContract]
public class MyTestMethodRequest
{
[MessageBodyMember( Namespace = "http://datacontract" )]
public MyType MyType;
}
[MessageContract]
public class MyTestMethodResponse
{
[MessageBodyMember( Namespace = "http://datacontract" )]
public MyOtherType MyOtherType;
}
Then change the signature of your service operation to the following.
[OperationContract]
public MyTestMethodResponse MyTestMethod( MyTestMethodRequest request )
{
return new MyTestMethodResponse {
MyOtherType = new MyOtherType {
OtherStringValue = "bar"
}
};
}
Now if you example the SOAP messages you should see the following:
Request
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"
s:mustUnderstand="1">http://servicecontract/TestService/MyTestMethod</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyTestMethodRequest xmlns="http://servicecontract">
<MyType StringValue="foo" xmlns="http://datacontract" />
</MyTestMethodRequest>
</s:Body>
</s:Envelope>
Response
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyTestMethodResponse xmlns="http://servicecontract">
<MyOtherType OtherStringValue="bar" xmlns="http://datacontract" />
</MyTestMethodResponse>
</s:Body>
</s:Envelope>
I don't know why WCF ignores XmlRoot, so I can't answer that part of your question. But I do have a couple ways to solve the problem.
start with WSDL first.
If you have a particular set of XML namespaces you would like to apply to the messages that get sent and receieved, use WSDL and XML Schema to explicitly specify them.
Then, generate the Server-side stub code, or the client-side proxy code, directly from that WSDL via the svcutil.exe tool.
use a custom ServiceHost
The other option open to you, described at this link, is to use a custom ServiceHost that overrides WCF's decision to disregard the XmlRoot or XmlType attributes on message types.
If you choose to go for the WSDL-First approach, the WSDL should look like this:
<?xml version="1.0" encoding="utf-8" ?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="urn:The-Service-namespace"
xmlns:tns="urn:The-Service-namespace"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:n0="urn:The-Request-namespace"
xmlns:n1="urn:The-Response-namespace"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
elementFormDefault= "unqualified"
>
<types>
<s:schema targetNamespace="urn:The-Request-namespace" >
<s:complexType name="Type1">
<s:sequence>
<s:element name="x" minOccurs="1" maxOccurs="1" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="Type1" type="n0:Type1" />
</s:schema>
<s:schema targetNamespace="urn:The-Response-namespace" >
<s:complexType name="Type2">
<s:sequence>
<s:element name="x" minOccurs="1" maxOccurs="1" nillable="false" type="s:string"/>
<s:element name="y" minOccurs="1" maxOccurs="1" nillable="false" type="s:int"/>
<s:element name="z" minOccurs="1" maxOccurs="1" nillable="false" type="s:boolean" />
</s:sequence>
</s:complexType>
<s:element name="Type2" type="n1:Type2" />
</s:schema>
</types>
<message name="RequestMessage">
<part name="inPart1" element="n0:Type1" />
</message>
<message name="ResponseMessage">
<part name="outPart1" element="n1:Type2" />
</message>
<portType name="PortTypeName">
<operation name="Method1">
<input message="tns:RequestMessage" />
<output message="tns:ResponseMessage" />
</operation>
</portType>
<binding name="InterfaceName" type="tns:PortTypeName">
<soap:binding
transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
<operation name="Method1">
<soap:operation soapAction="" style="document" />
<input> <soap:body use="literal" /> </input>
<output> <soap:body use="literal" /> </output>
</operation>
</binding>
</definitions>
This WSDL is very simple - it defines a single operation, with a single request message and a single response message.
Notice there are three xml namespaces:
urn:The-Service-namespace
used for the element that wraps the request and response - the first element inside the <SOAP:body>
urn:The-Request-namespace
used for the element wrapped inside that request wrapper, which gets deserialized into an instance of Type1.
urn:The-Response-namespace
used for the element wrapped inside that response wrapper, which gets deserialized into an instance of Type2.
If your web services interface is more complicated, has more operations and consequently more request and response message types, you can add more namespaces, if you like, for all those additional types.