I have a SOAP message like following:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:SaveMethod xmlns:ns1="urn:MyService" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<data xsi:type="xsd:string">
<![CDATA[
<?xml version='1.0' encoding='iso-8859-1'?>
<test>123</test>
]]>
</data>
</ns1:SaveMethod>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
My WCF is working fine when the SaveMethod tag is without prefix e.g.
<SaveMethod>
<data xsi:type="xsd:string">
etc.
But since i am not able to edit the SOAP message i need to find out how to make the SaveMethod accept the tag with prefix ns1.
Btw my method is as follows:
public void SaveMethod(String data){
// do something
}
Maybe i can do something on the client-side (HttpWebRequest used btw) ??
Thank you very much
Related
I have an XML as below
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns="http://com/uhg/uht/uhtSoapMsg_V1"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<uhtHeader
xmlns="http://com/uhg/uht/uhtHeader_V1">
<consumer>COMET</consumer>
<auditId></auditId>
<sendTimestamp>2020-09-03T18:15:40.942-05:00</sendTimestamp>
<environment>P</environment>
<businessService version="24">getClaimHistory</businessService>
<status>success</status>
</uhtHeader>
</env:Header>
<env:Body>
<srvcRspn
xmlns="http://com/uhg/uht/getClaimHistory_V24">
<srvcErrList arrayType="srvcErrOccur[1]" type="Array">
<srvcErrOccur>
<orig>Foundation</orig>
<rtnCd>00</rtnCd>
<explCd>000</explCd>
<desc></desc>
</srvcErrOccur>
</SrvcErrList>
</srvcRspn>
</env:Body>
</env:Envelope>
I want to remove all the attribute values with "http" like below:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns=""
xmlns:env="">
<env:Header>
<uhtHeader
xmlns="">
<consumer>COMET</consumer>
<auditId></auditId>
<sendTimestamp>2020-09-03T18:15:40.942-05:00</sendTimestamp>
<environment>P</environment>
<businessService version="24">getClaimHistory</businessService>
<status>success</status>
</uhtHeader>
</env:Header>
<env:Body>
<srvcRspn
xmlns="">
<srvcErrList arrayType="srvcErrOccur[1]" type="Array">
<srvcErrOccur>
<orig>Foundation</orig>
<rtnCd>00</rtnCd>
<explCd>000</explCd>
<desc></desc>
</srvcErrOccur>
</SrvcErrList>
</srvcRspn>
</env:Body>
</env:Envelope>
I have tried several ways but none of them has worked for me. Can anyone suggest what is fastest way to do it in VB.NET/C#.
The actual response is very large (approx 100000 lines of XML minimum) and using for each will consume a good amount of time. Is there any parsing method or LINQ query method which can do it faster.
I got the way to do it using Regex as below:
Return Regex.Replace(xmlDoc, "((?<=<|<\/)|(?<= ))[A-Za-z0-9]+:| xmlns(:[A-Za-z0-9]+)?="".*?""", "")
It serves my purpose completely. Thanks Cleptus for your quick reference.
I am trying to consume a service .
Can any one help me how to generate a soap request as follows.
i want to construct a class and then serialize the class using soap formator and then post it to my service. I tried with the some online help but could not able to generate the required soap xml.
i am bit confused about the implementation .Can any one help me on this.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:iot="http://services.singp.com>
<soapenv:Header/>
<soapenv:Body>
<iot.performService>
<iot.input>
<iot.gsh><![CDATA[
<header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://services.singp.com">
<GUID></GUID>
<CustID></CustID>
<RequestName></RequestName>
<TimeStamp>2017-06-09T10:49:03.49-05:00</TimeStamp>
</header>
]]></iot.gsh>
<iot.Body><![CDATA[
<CustStatus xmlns="http://services.singp.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CustStatusAttributes>
<CustID>str1234</CustID>
<Action>str1234</Action>
</CustStatusAttributes>
<CustStatusInformation>
<ClientOrderNumber>745</ClientOrderNumber>
</CustStatusInformation>
</CustStatus>
]]></iot.Body>
</iot.input>
</iot.performService>
</soapenv:Body>
</soapenv:Envelope>
I'm having hard-time fixing this little problem of ampersand (&) in the url... I'm serializing XML as shown below...
var ser = new XmlSerializer(typeof(response));
using (var reader = XmlReader.Create(url))
{
response employeeResults = (response)ser.Deserialize(reader); //<<error when i pass with ampersand
}
the above codes works fine if there is no & in the url otherwise it throws me an error (see below)
i have no problem serializing this url:
http://api.host.com/api/employees.xml/?&search=john
I'm having problem with this url:
http://api.host.com/api/employees.xml/?&max=20&page=10
The error i'm getting is:
`There is an error in XML document (1, 389).`
PS: I did tried passing & and also tried with & or #026 or & - no luck.
This XML isn't well-formed:
<?xml version="1.0"?>
<response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Api">
<meta>
<status>200</status>
<message />
<resultSet>
<Checked>true</Checked>
</resultSet>
<pagination>
<count>1</count>
<page>1</page>
<max>1</max>
<curUri>http://api.host.com/employee.xml/?&max=5</curUri>
<prevUri i:nil="true"/>
<nextUri>http://api.host.com/employee.xml/?&max=5&page=2</nextUri>
</pagination>
</meta>
<results i:type="ArrayOfemployeeItem">
<empItem>
<Id>CTR3242</Id>
<name>john</name>
......
</empItem>
</results>
</response>
You must escape & character or put entire string in CDATA, e.g.:
<?xml version="1.0"?>
<response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Api">
<meta>
<status>200</status>
<message />
<resultSet>
<Checked>true</Checked>
</resultSet>
<pagination>
<count>1</count>
<page>1</page>
<max>1</max>
<curUri><![CDATA[http://api.host.com/employee.xml/?&max=5]]></curUri>
<prevUri i:nil="true"/>
<nextUri><![CDATA[http://api.host.com/employee.xml/?&max=5&page=2]]></nextUri>
</pagination>
</meta>
<results i:type="ArrayOfemployeeItem">
<empItem>
<Id>CTR3242</Id>
<name>john</name>
......
</empItem>
</results>
</response>
If you are dealing with some third-party system and not able to get proper XML response, you have to do some pre-processing.
Maybe the simplest way is just replace all & with & using string.Replace method.
Or use this regex &(?!amp;) to replace all & excluding correct ones like &.
Have you tried to wrap the Attribute with <![CDATA[yourAttribute]]> ?
& is not allowed in xml
deserialize-xml-with-ampersand-using-xmlserializer
Is it possible to remove the what appears to be automatic notificationRequestResponse node from the response?
<?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>
<notificationRequestResponse xmlns="...">
<notificationResponse xmlns="...">
<success xmlns="">boolean</success>
<fault xmlns="">
...
</fault>
</notificationResponse>
</notificationRequestResponse>
</soap:Body>
</soap:Envelope>
I need to return the below:
<?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>
<notificationResponse xmlns="...">
<success xmlns="">boolean</success>
<fault xmlns="">
...
</fault>
</notificationResponse>
</soap:Body>
</soap:Envelope>
I want the notificationResponse to be the root of the response!
The WebMethod currently has no logic but:
return new notificationResponse()
Where is the notificationRequestResponse coming from? I can rename it using WebMethod SoapDocumentMethod(ResponseElementName="new name") but I want it gone. Working to a provided spec and have no choice.
Appreciated.
Found the answer...
SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)
I have below Soap response XML string
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header />
<soapenv:Body>
<qu:quotationResponse xmlns:qu="http://Reliance_RENEWAL_Quotation/IRenewal_Quotation">
<response><?xml version="1.0" encoding="UTF-8"?>
<RENEWAL-QUOTATION-RESPONSE>
<MESSAGE-DATA>
<ContractType>XYZ </ContractType>
<PremiumAmount>10000</PremiumAmount>
<PremiumSuspense>0.0</PremiumSuspense>
<NetAmmount>10000.0</NetAmmount>
<ContractPremiumStatus>Surrender </ContractPremiumStatus>
<ContractOwnerClientNumber>0501234</ContractOwnerClientNumber>
<OwnerName>SUDZ</OwnerName>
<LifeAssuredClientNumber>12312312</LifeAssuredClientNumber>
<LifeAssuredName>SUDZ </LifeAssuredName>
<PaidTodate>20110731</PaidTodate>
<ReinstatementFee>0.0</ReinstatementFee>
<ContractNumber>1122112211</ContractNumber>
</MESSAGE-DATA>
<ERROR-DETAILS>
<ErrorCode>No Errors</ErrorCode>
<ErrorDesc></ErrorDesc>
</ERROR-DETAILS>
</RENEWAL-QUOTATION-RESPONSE>
</response>
</qu:quotationResponse>
</soapenv:Body>
</soapenv:Envelope>
I need the value of ContractType, NetAmount etc
I tried but not able to parse.
What is best the way to parse above xml.
Please help.