Using SOAP in C# - c#

How can I access to a web service using SOAP in C# and get data from it? The request template is as follows:
POST /webservice/TsePublicV2.asmx HTTP/1.1
Host: service.tsetmc.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<MarketValue xmlns="http://tsetmc.com/">
<UserName>string</UserName>
<Password>string</Password>
</MarketValue>
</soap12:Body>
</soap12:Envelope>
The Response template is as follows:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<MarketValueResponse xmlns="http://tsetmc.com/">
<MarketValueResult>decimal</MarketValueResult>
</MarketValueResponse>
</soap12:Body>
</soap12:Envelope>

Related

Create Web Service for get soap messages

Actually, I had to make the request.
But service providers will not test sending any messages until after going through certain steps
So I need to create a website to test the messages I send.
How can I create a web service to receive soap messages below?
Content-ID: <ebxhmheader111#example.com>
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd"
xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://www.oasis-open.org/committees/ebxml-msg/schema/envelope.xsd
http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd
http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd">
<SOAP:Header>
<eb:MessageHeader SOAP:mustUnderstand="1" eb:version="2.0">
<eb:From>
<eb:PartyId>urn:duns:123456789</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId>urn:duns:912345678</eb:PartyId>
</eb:To>
<eb:CPAId>20001209-133003-28572</eb:CPAId>
<eb:ConversationId>20001209-133003-28572</eb:ConversationId>
<eb:Service>urn:services:SupplierOrderProcessing</eb:Service>
<eb:Action>NewOrder</eb:Action>
<eb:MessageData>
<eb:MessageId>20001209-133003-28572#example.com</eb:MessageId>
<eb:Timestamp>2001-02-15T11:12:12</eb:Timestamp>
</eb:MessageData>
</eb:MessageHeader>
</SOAP:Header>
<SOAP:Body>
<eb:Manifest eb:version="2.0">
<eb:Reference xlink:href="cid:ebxmlpayload111#example.com" xlink:role="XLinkRole" xlink:type="simple">
<eb:Description xml:lang="en-US">Purchase Order 1</eb:Description>
</eb:Reference>
</eb:Manifest>
</SOAP:Body>
</SOAP:Envelope>
--BoundarY
Content-ID: <ebxmlpayload111#example.com>
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<purchase_order>
<po_number>1</po_number>
<part_number>123</part_number>
<price currency="USD">500.00</price>
</purchase_order>
--BoundarY––

provide data into <tag> xml xml </tag> for a C# web service

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>

Is there some way I can send the SoapAction header within the xml request itself

I can send the Basic Authentication request within the xml itself without even writing something like
request.headers.add("");
and adding like this
<?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:Header>
<Authentication xmlns="http://tempuri.org/">
<Password>string</Password>
<UserName>string</UserName>
</Authentication>
</soap:Header>
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
Similarly I want to set the SOAPAction within the header xml itself instead of writing
request.headers.add("SOAPAction","someAction");
Somewhat like this
<?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:Header>
<SOAPAction>http://abc/xyz/test</SOAPAction>
<Authentication xmlns="http://tempuri.org/">
<Password>string</Password>
<UserName>string</UserName>
</Authentication>
</soap:Header>
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
Please guide me that How it can be achieved?

Azure storage REST group transactions - one of the request inputs is out of range

I'm trying my hand at entity group transactions with a very simple request, but keep getting a "400 (one of the request inputs is out of range)" error code in the response. Here's the string-serialized HttpRequestMessage:
Method: POST, RequestUri: 'http://127.0.0.1:10002/$batch?', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
x-ms-date: Tue, 21 Oct 2014 18:49:09 GMT
x-ms-version: 2014-02-14
Authorization: SharedKeyLite devstoreaccount1:vdQ+5/Kmw43u+DcqpWCX14n24WG8hsubtTK5pnK1xO8=
Content-Type: multipart/mixed; boundary=batch_f351702c-c8c8-48c6-af2c-91b809c651ce
Content-Length: 212
}
And the string-serialized request content:
--batch_f351702c-c8c8-48c6-af2c-91b809c651ce
Content-Type: application/http
Content-Transfer-Encoding: binary
GET http://127.0.0.1:10002/batchTable() HTTP/1.1
--batch_f351702c-c8c8-48c6-af2c-91b809c651ce--
The response from the server:
StatusCode: 400, ReasonPhrase: 'One of the request inputs is out of range.', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
x-ms-request-id: 43fea847-2226-4dcf-ad62-bdb7cc0af256
Date: Wed, 22 Oct 2014 00:00:06 GMT
Server: Microsoft-HTTPAPI/2.0
Content-Length: 325
Content-Type: application/xml
}
response content:
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>OutOfRangeInput</m:code><m:message xml:lang="en-US">One of the request inputs is out of range.
RequestId:43fea847-2226-4dcf-ad62-bdb7cc0af256
Time:2014-10-22T00:00:06.3046099Z</m:message></m:error>
Any idea what the problem could be?
Thanks!
Edit: Messing up the authorization header doesn't cause a 403 error, in case that helps.
Edit 2: I also get no error if I try batching a single insert - but the insert also doesn't take place:
Method: POST, RequestUri: 'http://127.0.0.1:10002/devstoreaccount1/$batch?', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
Accept: application/atom+xml
x-ms-date: Wed, 22 Oct 2014 16:38:34 GMT
x-ms-version: 2014-02-14
DataServiceVersion: 1.0
MaxDataServiceVersion: 3.0
Authorization: SharedKeyLite devstoreaccount1:Eb4JHmCsuL6aLMTGEWs+gt23zbKjAdYjO12YmeYHjf0=
Content-Type: multipart/mixed; boundary=batch_boundary
Content-Length: 1008
}
Content.ToString():
--batch_boundary
Content-Type: multipart/mixed; boundary="changeset_boundary"
Content-Length: 885
--changeset_boundary
Content-Type: application/http
Content-Transfer-Encoding: binary
POST http://127.0.0.1:10002/devstoreaccount1/batchTable? HTTP/1.1
Content-ID: 1
Content-Type: application/atom+xml;type=entry
Content-Length: 559
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title />
<updated>2014-10-22T16:38:34.6393109Z</updated>
<author>
<name />
</author>
<id />
<content type="application/xml">
<m:properties>
<d:PartitionKey m:type="Edm.String">foo</d:PartitionKey>
<d:RowKey m:type="Edm.String">foo</d:RowKey>
<d:IntVal m:type="Edm.Int32">1</d:IntVal>
</m:properties>
</content>
</entry>
--changeset_boundary--
--batch_boundary--
The issue was that the URI was http://127.0.0.1:10002/$batch instead of http://127.0.0.1:10002/devstoreaccount1/$batch. sigh
It looks like you are using an older version of Azure Storage Emulator, which does not support 2014-02-14 version. Could you please make sure your Emulator version is at least 3.2? If it is not, please upgrade to the latest version.

Remove the response wrapper from web service response?

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)

Categories