SOAP fault message - c#

I have to send a SOAP fault message over HTTP to another web service if something goes wrong with a server, so I have this code:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Response status="1">
<Description>DESC</Description>
<Errors>
<Error>500</Error>
</Errors>
</Response>
</soapenv:Body>
</soapenv:Envelope>
Is this a properly formatted SOAP fault message?

Is this a properly formatted SOAP fault message?
No it isn't. It should look something like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>...</faultcode>
<faultstring>...</faultstring>
<detail>...</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The SOAP specification specifies what a fault is. Yours looks like an error result object of some sort which has some disadvantages as explained here for example.
Your WS framework should properly generate faults if you throw exceptions. If you are not using a framework but building the fault in some other way, then it must look like in my example above or it can't be called a SOAP fault.

Hey Bogdan I wrote this code and works like a charm!
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>500</faultcode>
<faultstring>SERVER ERROR</faultstring>
<detail>
<Response_status>1</Response_status>
<Description>DESCRIPTION</Description>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
But another question how to send a SOAP success message with a http code 200 an also I have to have some additional parameters in the message, this is a part of it
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<Response_status>0</Response_status>
<Description>SUCCESS</Description>
</soap:Body>
</soap:Envelope>
So with this also I have to send code 200, how to write that can I write it like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>200</faultcode>
<faultstring>OK</faultstring>
<detail>
<Response_status>0</Response_status>
<Description>SUCCESS</Description>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

Related

c# send SOAP request with headers

I need to send an custom header mentioned below and get response from the proxy client. could some please share some basic sample code to achive the same.
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ses="http://xml.amadeus.com/2010/06/Session_v3">
<soap:Header>
<add:MessageID xmlns:add="http://www.w3.org/2005/08/addressing">0685482c-7f32-46b6-b27f-3149935b9307</add:MessageID>
<add:Action xmlns:add="http://www.w3.org/2005/08/addressing">http://webservices.amadeus.com/Hotel_MultiSingleAvailability_10.0</add:Action>
<add:To xmlns:add="http://www.w3.org/2005/08/addressing">https://noded5.test.webservices.amadeus.com/1ASIWPOC1A</add:To>
<link:TransactionFlowLink xmlns:link="http://wsdl.amadeus.com/2010/06/ws/Link_v1" />
<oas:Security xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<oas:UsernameToken xmlns:oas1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" oas1:Id="UsernameToken-1">
<oas:Username></oas:Username>
<oas:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">RjJmUSsjczI=</oas:Nonce>
<oas:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">ZmJhZTdhY2E0YzdkYjIyODFkNDY2Y2RjZDYxN2MyZDlkYTE5NWJkYg==</oas:Password>
<oas1:Created>2022-09-08T18:27:59.86Z</oas1:Created>
</oas:UsernameToken>
</oas:Security>
<AMA_SecurityHostedUser xmlns="http://xml.amadeus.com/2010/06/Security_v1">
<UserID AgentDutyCode="SU" POS_Type="1" PseudoCityCode="" RequestorType="U" />
</AMA_SecurityHostedUser>
</soap:Header>
</soap:Envelope>

How change namespace and prefix in WCF

My customer wants to a web service for integration. They send me the documentation and I created a WCF Service with methods.
But there are namespaces and prefixs problem. I didn't find any solution and I didn't find any suggest. For example there is a different tag (
Customer will send request like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://ws.common.haciosman.com">
<soapenv:Header />
<soap:Body>
<ws:getSystemStatus/>
</soap:Body>
</soap:Envelope>
Customer wants to response like that:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header/>
<soapenv:Body>
<ns:getSystemStatusResponse xmlns:ns="http://ws.common.haciosman.com">
<ns:return xsi:type="ax21:OutputMessage" xmlns:ax21="http://ws.common.haciosman.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax21:code>200</ax21:code>
<ax21:description>Success</ax21:description>
</ns:return>
</ns:getSystemStatusResponse>
</soapenv:Body>
</soapenv:Envelope>
Okay, I created a service but namespace and prefix not match. My service response like that:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<getSystemStatusResponse>
<getSystemStatusResult xmlns:a="http://schemas.datacontract.org/2004/07/WCFLocal.cls" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:code>200</a:code>
<a:description>Success</a:description>
</getSystemStatusResult>
</getSystemStatusResponse>
</s:Body>
</s:Envelope>
As you see, tags are different. What is wrong and how can I change prefix in WCF Service?
Thanks for your reply.

Custom fault type for an ASP.NET webservice

I am developing a webservice in C#, ASP.NET. By default, when my webservice throws exception, using
throw new SoapException("ERROR_MESSAGE", SoapException.ClientFaultCode);
This outputs the following xml:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>ERROR_MESSAGE</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
However, I have to implement a custom fault type that uses different xml:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:cst="http://cust.om/Namespace">
<cst:Fault>
<cst:errorMessage>ERROR_MESSAGE</cst:errorMessage>
</cst:Fault>
</soap:Body>
</soap:Envelope>
They expect that this fault type appears also in the wsdl file that is generated by http-GETting ?wsdl, surfacing there as element.
Is this even possible? Well, everything is possible by rewriting the exiting stream with replaced string, but I'd prefer less brutal approach. Besides, that kind of fix would not cause the elements to appear in the auto-generated wsdl spec.

AdWords API : client list for non MCC account

I want to get a list of AdWords clients assigned to authenticated account (i use OAuth).
First attempt was to use ServicedAccountService and this XML request
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<RequestHeader xmlns="https://adwords.google.com/api/adwords/mcm/v201109">
<developerToken xmlns="https://adwords.google.com/api/adwords/mcm/v201109">[[DEV_TOKEN]]</developerToken>
</RequestHeader>
</soap:Header>
<soap:Body>
<get xmlns="https://adwords.google.com/api/adwords/mcm/v201109">
<selector>
<enablePaging>false</enablePaging>
</selector>
</get>
</soap:Body>
</soap:Envelope>
But it works only for MCC accounts. For regular google account i got empty dataset
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ResponseHeader xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201109" xmlns="https://adwords.google.com/api/adwords/mcm/v201109">
<ns2:requestId>0004bc71cee633d00aecb0aa000060ca</ns2:requestId>
<ns2:serviceName>ServicedAccountService</ns2:serviceName>
<ns2:methodName>get</ns2:methodName>
<ns2:operations>0</ns2:operations>
<ns2:responseTime>230</ns2:responseTime>
<ns2:units>0</ns2:units>
</ResponseHeader>
</soap:Header>
<soap:Body>
<getResponse xmlns="https://adwords.google.com/api/adwords/mcm/v201109" xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201109">
<rval>
<accounts>
<customerId>0</customerId>
<canManageClients>false</canManageClients>
</accounts>
</rval>
</getResponse>
</soap:Body>
</soap:Envelope>
I googled a lot, and finally found that i can use other XML (InfoService) for both MCC and non MCC accounts.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<RequestHeader xmlns="https://adwords.google.com/api/adwords/info/v201109">
<developerToken xmlns="https://adwords.google.com/api/adwords/cm/v201109">[[DEV_TOKEN]]</developerToken>
</RequestHeader>
</soap:Header>
<soap:Body>
<get xmlns="https://adwords.google.com/api/adwords/info/v201109">
<selector>
<dateRange>
<min xmlns="https://adwords.google.com/api/adwords/cm/v201109">[[START_DATE]]</min>
<max xmlns="https://adwords.google.com/api/adwords/cm/v201109">[[END_DATE]]</max>
</dateRange>
<includeSubAccounts>true</includeSubAccounts>
<apiUsageType>UNIT_COUNT_FOR_CLIENTS</apiUsageType>
</selector>
</get>
</soap:Body>
</soap:Envelope>
But data returned is incorrect - not all accounts are listed. Or no data returned at all.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ResponseHeader xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201109" xmlns="https://adwords.google.com/api/adwords/info/v201109">
<ns2:requestId>0004bc7121a910e80a97030d000051e7</ns2:requestId>
<ns2:serviceName>InfoService</ns2:serviceName>
<ns2:methodName>get</ns2:methodName>
<ns2:operations>1</ns2:operations>
<ns2:responseTime>1206</ns2:responseTime>
<ns2:units>1</ns2:units>
</ResponseHeader>
</soap:Header>
<soap:Body>
<getResponse xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201109" xmlns="https://adwords.google.com/api/adwords/info/v201109">
<rval>
<cost>0</cost>
</rval>
</getResponse>
</soap:Body>
</soap:Envelope>
Is there any other way to get client list for AdWords account? Thanks a lot.
I've also encountered this problem, and can confirm that it's not the correct behaviour of the ServicedAccountService; it's a "known issue that will be resolved in future": If you link your basic account to an MCC, then you can authenticate with the basic account and use the ServicedAccountService to obtain the account details, but if the account isn't linked then you'll get this problem.
If you just want to obtain the customer id for an account, you can also use the InfoService, which doesn't suffer from the same issue.

How to make C# web service produce soapenv namespace instead of soap?

Is there a way to make a C#/.NET web service which normally produces XML like this
<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:Header>
<DHeader xmlns="http://www.abc.com" />
</soap:Header>
<soap:Body>
<Response xmlns="http://www.abc.com">
<Result>
<ErrorObject ObjectID="string" ErrorCode="" />
</Result>
</Response>
</soap:Body>
</soap:Envelope>
to produce XML like this.
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapv:Header>
<DHeader xmlns="http://www.abc.com" />
</soapenv:Header>
<soapenv:Body>
<Response xmlns="http://www.abc.com">
<Result>
<ErrorObject ObjectID="string" ErrorCode="" />
</Result>
</Response>
</soapenv:Body>
</soapenv:Envelope>
This trying solve a problem with an AXIS client consuming a .NET web service. AXIS is choking on the soap namespace and needs a soapenv namespace. Changing the AXIS side is not possible.
any thoughts or comments would be great.
Here is the exact error as requested.
line -1: Element Envelope#http://www.w3.org/2003/05/soap-envelope is not a valid Envelope#http://schemas.xmlsoap.org/soap/envelope/ document or a valid substitution.
soapenv is not a namespace - it's a namespace prefix.
As long as the prefixes refer to the same namespace, soap and soapenv refer to the same thing, and have the identical meaning.
It seems extremely unlikely that any version of AXIS is so badly broken as to treat the prefixes specially. You should assume you have a different problem. Please post the exact error you're receiving.

Categories

Resources