Return Multiple Elements in a SOAP Response - c#

I'm using:
.NET Core 3.0 (C#)
SOAPCore for serialization
SQL Server
I have a pre-built SOAP service from a legacy system that is providing a request structured with two (2) Elements (RequestHeader and SearchPolicyDetails):
<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>
<RequestHeader xmlns="http://xxx">
<RequestDate>2019-11-18+05:30</RequestDate>
<SourceSystemRequestNo>1001</SourceSystemRequestNo>
</RequestHeader>
<SearchPolicyDetails xmlns="http://xxx">
<policyNumber>xxxxxxxx</policyNumber>
<asOfDate>2019-12-24</asOfDate>
</SearchPolicyDetails>
</soap:Body>
</soap:Envelope>
I can get both to run if I use a singular endpoint on my SOAP Endpoints (I.e. RequestHeader returns the data I want or SearchPolicyDetails returns the data I want. However I would like to get them to run consecutively so i can return the data from each into a single response:
<s:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<RequestHeaderResponse>
{{DATA}}
</RequestHeaderResponse>
<SearchPolicyDetailsResponse>
{{DATA}}
</SearchPolicyDetailsResponse>
</s:Body>
</s:Envelope>
Is this possible since I do not know if it would be possible to get the team who built the legacy system to update the request objects. Currently if I run them in the same request the payload only returns the first Element's data.

Related

Are namespaces taken into account when contacting a soap web service?

I have some existing code which uses a third party SOAP client to retrieve data from another third party web service. As we switched to a new data provider, we also switched to their new endpoint. We found out that our current requests are all failing and the error we get in return is "Policy Falsified".
I have used SOAP UI to test the new web service and I can successfully obtain data this way. That is why I compared the two soap messages and found out that the problem is likely with the URI used for the soap namespace.
Code generated soap message
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Request>
//...
</Request>
</s:Body>
</s:Envelope>
Working message with SOAP UI
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Request>
//...
</Request>
</soap:Body>
</soap:Envelope>
The only differences in these messages are the namespace prefixes and the soap namespace (the data inside the request tag are identical). I would like to know if this web service is rejecting my soap message purely by the soap namespace that it's using, or that something else might play a problem?
Obviously I am likely going to need to make my own implementation to generate the soap messages myself, but I'd still like to know if the webservice is set to only accept messages with that specific soap namespace or that it's some other kind of issue?

EWS HttpHeader Content-type

I've followed Microsoft's Get started with EWS Managed API client applications tutorial, in an effort to build an application that will get specific items from a mailbox on an Exchange server.
It seems that after the initial auto-discover operations succeed, no matter what kind of request I send through the API, I get a response back containing the following:
HTTP/1.1 415 Cannot process the message because the content type 'text/plain; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.
With Microsoft.Exchange.WebServices.Data.ExchangeService.TraceEnabled = true, the trace of a typical request looks like this (this one is generated by calling Folder.Bind(service, "IT", propSet)):
<?xml version="1.0" encoding="utf-16"?>
<Trace Tag="EwsRequest" Tid="1" Time="2019-03-01 14:42:02Z" Version="15.0.913.15">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013" />
</soap:Header>
<soap:Body>
<m:GetFolder>
<m:FolderShape>
<t:BaseShape>IdOnly</t:BaseShape>
</m:FolderShape>
<m:FolderIds>
<t:FolderId Id="IT" />
</m:FolderIds>
</m:GetFolder>
</soap:Body>
</soap:Envelope>
</Trace>
It looks like the Content-Type header is missing altogether, so the server sees the request as text/plain; charset=utf-8. It shouldn't be a problem to add Content-Type: text/xml; charset=utf-8 to requests that the ExchangeService object makes, but the member Dictionary HttpHeaders is not settable (see the interface in ExchangeServiceBase).
Any idea how I can either send the server an acceptable request with the EWS Managed API, or configure the target Exchange server so that it accepts the requests I'm sending? I've come across lots of related SO questions, but none with an actual answer to this problem.
I was getting the same error and the only clue I could find was this thread.
I eventually fixed it by switching to Microsoft.Exchange.WebServices.NETStandard -v 1.1.3 (from -v 2.0.0-beta1).

How do I make my ASP.NET website to pull data from an API?

I can connect to my API using SoapUI and it returns a string of tournaments. My C#/ASP.NET website needs to do the following:
The user clicks an import button.
The import button pulls a string of tournaments from the API. (How do I use C# to call the API)?
Parse the tournaments out of the string of data and save them to a database. (I have this part under control).
Here is what the Soap Envelope looks like:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:war="WarehouseServices/">
<soap:Header/>
<soap:Body>
<war:Warehouse>
<!--Optional:-->
<war:username></war:username>
<!--Optional:-->
<war:password></war:password>
<war:systemId></war:systemId>
<!--Optional:-->
<war:date></war:date>
<war:productGroupId></war:productGroupId>
</war:Warehouse>
</soap:Body>
</soap:Envelope>
Using the SoapUI I can pull the string of tournaments just fine, but how do I make C# do it?
I look forward to receiving your kind help and consideration. Long live our coders!

sending SOAP request in asp.net mvc3

I want to send following SOAP/XML request and get the SOAP response back in asp.net mvc/C#
<?xml
<soapenv:Envelope
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:myurn">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:fLocHistory 
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <HistRequest 
xsi:type="urn:SubMemLocationHistoryRequest">
            <MSID xsi:type="xsd:string">test</MSID>
            <AID xsi:type="xsd:int">2</AID>
            <MemMSISDN xsi:type="xsd:string">test</MemMSISDN>
         </HistRequest>
      </urn:fLocHistory>
   </soapenv:Body>
</soapenv:Envelope>
What is the better way to send request. I have seen example regarding MSXML2, WCF or asmx. If you could point some good starting tutorial. I have seen some examples here and here and here.

Soap web service and android client using ksoap protocal mismatch

I have and android client, that uses ksoap to communicate with a wsdl web service written in c# asp.net. I have a problem with matching the argument types between the web service and the client.
The web server expects to this kind of request (auto generated):
<?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>
<GetDetails xmlns="http://host.org/">
<event_id>int</event_id>
</GetDetails>
</soap:Body>
</soap:Envelope>
the client sends requests using ksoap, and they look like this:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<n0:GetDetails id="o0" c:root="1" xmlns:n0="http://tempuri.org">
<event_id i:type="d:int">1</event_id>
</n0:GetDetails>
</v:Body>
</v:Envelope>
For some reason the WS parses the following' client's request as 0 (I guess because of the additional type attributes - i:type="d:int") when the request is assembled manually to look like the first option, it works correctly.
How can i make the web service read the ksoap format correctly or how can i change it's expected format to look like ksoap request. (the web service soap protocol is auto generated).
Well the solution has 2 parts:
1. regarding removing the attribute types, I found the answer here:
using addMapping without the "i:type=" attribute in ksoap2 for android
I neede to set:
envelope.implicitTypes = true;
The name space has to end with a backspace, and i missed it.

Categories

Resources