I am writing a SoapCore web service in .NET Core 5.0 and I have successfully been able to execute the request via SOAPUI and get back a valid response. The only thing I don't like is that it puts unwanted prefixes in the repose message. for example in this response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Body>
<getMeterIntervalDataByTimeSliceResponse xmlns="http://tempuri.org/">
<getMeterIntervalDataByTimeSliceResult xmlns:d4p1="http://schemas.datacontract.org/2004/07/MeterDataWebService.Models" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:AccountId>1234567890</d4p1:AccountId>
<d4p1:ID>0</d4p1:ID>
<d4p1:IntervalEndTime>2020-12-22T15:30:57.3705724-05:00</d4p1:IntervalEndTime>
<d4p1:IntervalLengthInSeconds>PT5M</d4p1:IntervalLengthInSeconds>
<d4p1:Load>2345.8010350836185</d4p1:Load>
<d4p1:MeterChannel>1</d4p1:MeterChannel>
<d4p1:TimeZone>UT</d4p1:TimeZone>
<d4p1:UnitOfMeasure>KM</d4p1:UnitOfMeasure>
<d4p1:UtcOffset>0</d4p1:UtcOffset>
</getMeterIntervalDataByTimeSliceResult>
</getMeterIntervalDataByTimeSliceResponse>
</s:Body>
</s:Envelope>
How do I get rid of the "d4p1" prefix?
I figured it out. It was in my Startup.cs class.
app.UseSoapEndpoint("/Service.asmx", new
BasicHttpBindingg(), SoapSerializer.XmlSerializer);
I forgot to add the SoapSerializer.XmlSerializer part
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
I have a method in C# .NET 4.0 web service which accepts DataTable as on of the ByVal parameter.
This method is now being used in an xml application.
So, in the place of the datatable, I am getting as <Meta> xml xml </Meta>.
How should I pass the data in the form of xml to be able to use by datatable within the xml below?
I haven't found proper solutions for this on web.
POST /MyService/service.asmx HTTP/1.1
Host: xxxxxxxxxxxxx
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Upload"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Upload xmlns="http://tempuri.org/">
<IndexKey>string</IndexKey>
<YoMoney_Key>string</YoMoney_Key>
<buffer>base64Binary</buffer>
<strDocType>string</strDocType>
<append>boolean</append>
<revtype>string</revtype>
<strScanDateTime>string</strScanDateTime>
<UserID>string</UserID>
<Meta>xmlxml</Meta>
</Upload>
</soap:Body>
</soap:Envelope>
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 tried to test my svc service with SoapUI, but when I create the request, the method is been added like a part of him. but is not part of the request.
There's anyone know how to fixed ?
Here is an example of my request
<soap:Body>
<findSchedule> <!--findSchedule is the part that i want to remove-->
<request>
...
</request>
</findSchedule>
</soap:Body>
This is how the request has to look like.
<soap:Body>
<request>
...
</request>
</soap:Body>