We are integrating a service from a third party. They have recently upgraded their service, and now with the new wsdl, I keep getting "Illegal Request format for Element".
From my investigations the problem seems to be with the xmlns that is added on the main element. If I use SOAPUI and remove the xmlns from the main element, it works, however visual studio adds it automatically in accordance with whats defined in the wsdl.
What is interesting is that with their previous wsdl, the service works with the xmlns included, it is only with the new wsdl that it throws an exception.
In terms of the wsdl, all I know is that they used JD 12 and manually created the wsdl, however upon comparing it, it looks similar to the old one with the name in the xmlns being the only difference.
This is the request visual studio creates:
<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">
<extractacccategElement xmlns="http://gna160ws/Management.wsdl/types/">
<xSecurity>
<timekey></timekey>
<authkey></authkey>
<publkey></publkey>
<version>1.x</version>
</xSecurity>
<xRequest1>
<supplierno></supplierno>
</xRequest1>
</extractacccategElement>
</s:Body>
</s:Envelope>
With the "xmlns="http://gna160ws/Management.wsdl/types/"" causing the problem.
Response:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header/>
<env:Body>
<srvc:extractacccategElementResponse xmlns="http://gna160ws/Management" xmlns:srvc="http://gna160ws/Management">
<srvc:result>
<response1Out>
<origin>gna160.extractacccategElement</origin>
<invsql>1200</invsql>
<message>Illegal Request format for extractacccategElement.</message>
</response1Out>
</srvc:result>
</srvc:extractacccategElementResponse>
</env:Body>
</env:Envelope>
When submitting the same request, but without the xmlns, I get a valid response. Example:
<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">
<extractacccategElement>
<xSecurity>
<timekey></timekey>
<authkey></authkey>
<publkey></publkey>
<version>1.x</version>
</xSecurity>
<xRequest1>
<supplierno></supplierno>
</xRequest1>
</extractacccategElement>
</s:Body>
</s:Envelope>
Response:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<ns0:extractacccategElementResponse xmlns="http://gna160ws/Management" xmlns:srvc="http://gna160ws/Management">
<ns0:result>
<ns0:acccategOut>
<ns0:invsql>0</ns0:invsql>
<ns0:message>Success</ns0:message>
<ns0:origin>gna160pkg.ExtractAccCateg</ns0:origin>
<ns0:stage>1</ns0:stage>
<ns0:acccategcode>A</ns0:acccategcode>
<ns0:acccategname>AAA</ns0:acccategname>
</ns0:acccategOut>
</ns0:result>
</ns0:extractacccategElementResponse>
</env:Body>
</env:Envelope>
Additionally, if I add a qualifer after the xmlns then it also works??
Example:
xmlns:hello="http://gna160ws/Management.wsdl/types/"
I have been working collaboratively with the developer on their side and we have not yet been able to identify the problem.
If anyone could help or point me in the right direction, it would be greatly appreciated.
Did you update your service reference with the new WSDL?
Alternatively you can try this answer from Rick Strahl: override the following function to add a custom namespace.
protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer)
{
writer.WriteStartElement("soapenv", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
writer.WriteAttributeString("xmlns", "oas", null, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
writer.WriteAttributeString("xmlns", "v2", null, "http://www.royalmailgroup.com/api/ship/V2");
writer.WriteAttributeString("xmlns", "v1", null, "http://www.royalmailgroup.com/integration/core/V1");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
}
Link to his complete article
Hi I am new at WCF Soap services, I need to connect to a webserver use Xml-Rpc. First I tried to connect and got an error about "xml-rpc encoded" then I added Microsoft.Samples.XmlRpc to project. I can connect to the service but when I try to send Soap message I am getting :
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:hdr="urn:PASAHeader" xmlns:ns3="urn:PASAMnfGetFlowVehInfo_v2" xmlns:ns1="urn:PASAMnfGetFlowVehInfo" xmlns:ns2="urn:PASAMnfUpdatedFromSupplier" xmlns:ex="urn:PASAexploitationWS">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" id="_0">
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:VersionMismatch</faultcode>
<faultstring>SOAP version mismatch or invalid SOAP message</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am using that code to convert to xml-rpc
ChannelFactory<ServiceReference2.MnfGetFlowVehInfoPortTypeChannel> typeChannel = new ChannelFactory<ServiceReference2.MnfGetFlowVehInfoPortTypeChannel>(new WebHttpBinding(WebHttpSecurityMode.None), new EndpointAddress(uriAdress));
typeChannel.Endpoint.EndpointBehaviors.Add(new XmlRpcEndpointBehavior());
I tried to change the version using messageVersion in library but I couldn't handle it.Thanks
I have a .NET application that is consuming a Java WCF, and I need to change my Reference.cs to set the ServiceVersion, I don't know how I can do this.
Someone has some idea?
My SOAP XML should be:
<s:Header>
<ns:TocHeader>
<ns:Message>
<ns:X>
<ns1:ServiceVersion>12.05</ns1:ServiceVersion>
</ns:X>
</ns:Message>
</ns:TocHeader>
</s:Header>
The XML that .NET is generating:
<s:Header>
<ns:TocHeader xsi:nil="true"/>
</s:Header>
I use WCF to implement a client for a SOAP web service. The code is generated by "Add Service Reference" based on the WSDL file.
The elements of the SOAP request are defined in different namespaces.
Now, a sample message looks like this:
<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">
<myMethod xmlns="http://example.org/xsd/requests">
<RequestData>
<Foo xmlns="http://example.org/xsd/elements">some</Foo>
<Bar xmlns="http://example.org/xsd/elements">thing</Bar>
<Baz xmlns="http://example.org/xsd/elements">content</Baz>
<!-- .... more elements .... -->
</RequestData>
</myMethod>
</s:Body>
</s:Envelope>
which contains the redundant definition of the elements namespace. In order to reduce message size, I would prefer to have the namespace definitions at the top of the message, eg. like this:
<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"
xmlns:a="http://example.org/xsd/requests"
xmlns:b="http://example.org/xsd/elements">
<a:myMethod>
<a:RequestData>
<b:Foo>some</b:Foo>
<b:Bar>thing</b:Bar>
<b:Baz>content</b:Baz>
<!-- .... more elements .... -->
</a:RequestData>
</a:myMethod>
</s:Body>
</s:Envelope>
(I don't really care which parent element defines the namespaces, so any way to move the namespace definitions to Envelope, Body or MyMethod would be okay for me.)
How can I achieve this?
EDIT: removed local xmlns definitions in second example (copy-paste mistake ;) )
We got a docs from our client specifying that our WCF service we developing should return responses like this one:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hsdq="http://site.gov/21398">
<soapenv:Header/>
<soapenv:Body>
<inf:getCarsResponse xmlns:inf="inf">
<hsdq:Message1/>
<hsdq:Message2>
<hsdq:ApplicationData>
...
</hsdq:ApplicationData>
<hsdq:ApplicationDocument/>
</hsdq:Message2>
</inf:getCarsResponse>
</soapenv:Body>
</soapenv:Envelope>
But response generated by our service is slightly different:
<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">
<getCarsResponse xmlns="inf">
<Message2 xmlns="http://site.gov/21398">
<ApplicationData>
...
</ApplicationData>
</Message2>
</getCarsResponse>
</s:Body>
</s:Envelope>
I know that I could fix missing of ApplicationDocument section and Header section. But how can I make my response be exact like provided?
I mean that I would like to configure xmlserializer to be possible:
1. Remove unnecessary xsi and xsd namespaces.
2. Rename envelope namespace s to soapenv.
3. hsdq namespace should be specified in root element and should be identified also by name not only by an url. (Compare in first response: xmlns:hsdq="http://site.gov/21398" and second response: xmlns="http://site.gov/21398"
I think I should use IDispatchMessageFormatter for that, but is seems too complicated for me that I couldn't use ut without any sample.
Thanks, guys!
I don't think you could do it. The namespace order of prefix should not matter to the server. You could write a custom encoder to swap namespaces but you should really check why the server rejects this, maybe it does not like something else.