How to add AuthHeader on gowsdl - go

I am integrating soap service with use gowsdl library.
I can't create auth header like this;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header>
<tem:AuthHeader>
<!--Optional:-->
<tem:UserName>?</tem:UserName>
<!--Optional:-->
<tem:Password>?</tem:Password>
</tem:AuthHeader>
</soapenv:Header>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>
I am using code generated by gowsdl
I will explain shortly;
AuthHeader in service.go
type AuthHeader struct {
UserName string `xml:"UserName,omitempty" json:"UserName,omitempty"`
Password string `xml:"Password,omitempty" json:"Password,omitempty"`
}
and I am using like this
authHeader := service.AuthHeader{
Password: Password,
UserName: Username,
}
header := struct {
AuthHeader service.AuthHeader `xml:"AuthHeader,omitempty" json:"AuthHeader,omitempty"`
}{
AuthHeader:authHeader,
}
And adding header like this;
soapClient := soap.NewClient(Url)
soapClient.AddHeader(header)
but it is not working! How can I solve this problem?

From the gowsdl package's example.go why not set the auth headers like so:
client := soap.NewClient(
Url,
soap.WithBasicAuth("usr", "psw"),
)

Related

When I try to retrieve the Attachment by ID, I get an ErrorItemNotFound response

My problem seems to be to a permission error. When I try to retrieve the Attachment by ID using an EWS Soap request, I get an ErrorItemNotFound response.
So I'm roughly following the GetAttachment Example from Microsoft -- http://learn.microsoft.com/en-us/outlook/add-ins/get-attachments-of-an-outlook-item
My WebService that receives the EWS Token, EWS URL, and Attachment ID is written in Python.
Here is what I have working.
I have an Outlook AddIn written in Javascript that responds to mail item selections.
I retrieve an EWS Token using the isRest=false option and
Office.context.mailbox.getCallbackTokenAsync(getEWSCallback,
options);
For mail that has an attachment, I extract information about the attachment including the attachment Id.
Here is a sample of the attachment information:
{
"id":
"XZkADdlMDAxOTFiLWZmMWYtNGI1Ni1iYmM2LTlhOTJjYTBmMTI1MQBGAAAAAAAO1b910PexQpLkqgde51DABwAyR2+p4hG4RbXOV7pJuYtiAAAAAAEMAAAyR2+p4hG4RbXOV7pJuYtiAABsXaGoAAABEgAQAJ8Lans/ZeZLrkpk6mQ/QQg=",
"name":
"xxxxxxxxxxx.docx",
"contentType":
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"size":
162008,
"attachmentType":
0,
"isInline":
false
}
I pass the EWS Token, EWS Url, and Attachment information to my webservice; which is written in Python.
My WebService constructs the soap request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="https://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013" />
</soap:Header>
<soap:Body>
<GetAttachment xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<AttachmentShape/>
<AttachmentIds>
<t:AttachmentId Id="XZkADdlMDAxOTFiLWZmMWYtNGI1Ni1iYmM2LTlhOTJjYTBmMTI1MQBGAAAAAAAO1b910PexQpLkqgde51DABwAyR2+p4hG4RbXOV7pJuYtiAAAAAAEMAAAyR2+p4hG4RbXOV7pJuYtiAABsXaGoAAABEgAQAJ8Lans/ZeZLrkpk6mQ/QQg="/>
</AttachmentIds>
</GetAttachment>
</soap:Body>
</soap:Envelope>
I then send a Webrequest with python:
authHeaders = {
'Authorization':
"Bearer " + ewsToken,
'Content-type':
'text/xml; charset=utf-8'
}
webResp = requests.post(url=ewsUrl, headers=authHeaders, data=requestString)
The response I get is below:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo
MajorVersion="15"
MinorVersion="20"
MajorBuildNumber="2430"
MinorBuildNumber="27"
Version="V2018_01_08"
xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:GetAttachmentResponse
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:GetAttachmentResponseMessage
ResponseClass="Error">
<m:MessageText>The specified object was not found in the store., The process failed to get the correct properties.</m:MessageText>
<m:ResponseCode>ErrorItemNotFound</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:Attachments/>
</m:GetAttachmentResponseMessage>
</m:ResponseMessages>
</m:GetAttachmentResponse>
</s:Body>
</s:Envelope>
My understanding is that the ErrorItemNotFound response indicates either (1) The item doesn't exists or (2) I don't have permission to access it.
If I use a corrupt EWS Token, I get a Http 401 error that indicates I'm not authorized to make the EWS Post. So I believe the Bearer authentication is working correctly.
Any thoughts or help?

how to access web service endpoint url without authentication from a oracle plsql procedure?

I have created a sample anonymous block which exposes a plsql procedure to get the employee details through the web service. We are obtaining the response properly , however we are able to access the endpoint url(http://localhost:8080/..) only if schema's username and password are provided in the url. How to access the url globally without any authentication?
we are using oracle 11g xdb server
End point url used in the code:
...
l_http_request := utl_http.begin_request(url =>http://PERU_WS:1234#localhost:8088/orawsv/PERU_WS/GETEMP_DETAILS', method => 'POST',http_version => 'HTTP/1.1');
...
SOAP Request:
`<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://xmlns.oracle.com/orawsv/PERU_WS/GETEMP_DETAILS"> <soapenv:Header/> <soapenv:Body> <get:GETEMP_DETAILSInput> <get:P_OUT-VARCHAR2-OUT/> <get:P_ID-NUMBER-IN>'||P_ID||'</get:P_ID-NUMBER-IN> </get:GETEMP_DETAILSInput> </soapenv:Body> </soapenv:Envelope>` (p_id=4)
SOAP Response:
PL/SQL procedure successfully completed.
Response> status_code: "200"
Response> reason_phrase: "OK"
Response> http_version: "HTTP/1.1"
Response> <?xml version="1.0" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GETEMP_DETAILSOutput xmlns="http://xmlns.oracle.com/orawsv/PERU_WS/GETEMP_DETAILS">
<P_OUT>Manju</P_OUT>
</GETEMP_DETAILSOutput>
</soap:Body>
</soap:Envelope>

Close AccountingPeriod in Zuora via SOAP

I am trying to call the update method of the Zuora Soap API so as to 'CloseAccountingPeriod'. What is the correct way to do this
require 'savon'
message = {'username' => 'username','password' => 'password' }
client = Savon.client(wsdl: 'zuora.a.75.0.wsdl')
response = client.call(:login, message: message)
#response = client.call :update do
soap.header = {
}
soap.body = {
:Status=> "closed",
:ids=>"4028e699235ea4de0123777131fd5d68"
}
end
The Zuora Soap looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv=
"http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ns1:SessionHeader xmlns:ns1=
"http://api.zuora.com/" soapenv:mustUnderstand="0">
<ns1:session>[replace with your session]</ns1:session>
</ns1:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<ns1:update xmlns:ns1="http://api.zuora.com/">
<ns1:zObjects xmlns:ns2="http://object.api.zuora.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns2:AccountingPeriod">
<ns2:Id>402892a83711418b01371142cc5801a9</ns2:Id>
<ns2:Status>Closed</ns2:Status>
</ns1:zObjects>
</ns1:update>
</soapenv:Body>
</soapenv:Envelope>
That example is correct
The minimum required data is
session key
32 char id of the AccountingPeriod
Status "Closed"

Bing Translation Api access via SOAP interface from Ruby

I'm trying to use Bing Translator SOAP API (due to in HTTP API I'm getting 414 "Request too long" for not so big requests due to UTF-8 serialization).
So, I'm playing with bing_translator gem source trying to switch it from HTTP inerface to SOAP one using Savon SOAP toolkit.
My workflow as follows (access token getting function not shown):
WSDL_URI = 'http://api.microsofttranslator.com/V2/soap.svc?wsdl'
get_access_token
client = Savon.client(wsdl: WSDL_URI, headers: {'Authorization' => "Bearer #{#access_token['access_token']}"})
params = {
'from' => 'ru',
'to' => 'en',
'text' => 'Это текст для перевода',
'category' => 'general',
'contentType' => 'text/plain'
}
result = client.call(:translate, message: params)
Then SOAP request executes:
SOAP request: http://api.microsofttranslator.com/V2/soap.svc
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=invest_amurobl_ru&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&Audience=http%3a%2f%2fapi.microsofttranslator.com&ExpiresOn=1381128612&Issuer=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&HMACSHA256=Mw41PMMgw2n6ZVaGRXtwfR0vwMJUyIMltIyd9pa9MqA%3d
SOAPAction: "http://api.microsofttranslator.com/V2/LanguageService/Translate"
Content-Type: text/xml;charset=UTF-8
Content-Length: 454
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://tempuri.org/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wsdl:Translate>
<to>en</to>
<text>Это текст для перевода</text>
<category>general</category>
<contentType>text/html</contentType>
<from>ru</from>
</wsdl:Translate>
</env:Body>
</env:Envelope>
And I'm getting error 500: Unhandled Service Exception
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-US">Unhandled Service Exception</faultstring>
<detail>
<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1</int>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
What's may be wrong? Can anyone who already using Bing Translator SOAP API to diff my soap-messages with yourself? Any advices to how to troubleshoot this.
Thanks for attention.
EDIT:
I've checked API with SoapUI, as #SteffenRoller advices and it works. Here is XML generated by SoapUI (values are inserted by hand):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://api.microsofttranslator.com/V2">
<soapenv:Header/>
<soapenv:Body>
<v2:Translate>
<!--Optional:-->
<v2:text>Текст, который я хочу перевести</v2:text>
<!--Optional:-->
<v2:from>ru</v2:from>
<!--Optional:-->
<v2:to>en</v2:to>
<!--Optional:-->
<v2:contentType>text/plain</v2:contentType>
<!--Optional:-->
<v2:category>general</v2:category>
</v2:Translate>
</soapenv:Body>
</soapenv:Envelope>
As you can see the only difference is that all the tags inside a <Body> are in the v2 namespace. In the XML, generated by Savon this namespace isn't present at all.
So, now question is: How to instruct Savon to use correct namespace for tags inside the message body?
Although, I think, this is a Savon bug, I'll file it to developers, as SoapUI have generated correct XML by the same WSDL, and Savon doesn't.
Okay. This is a known bug: Savon issue #340. It's related to composite WSDL files and won't bi fixed in current major release :-(
So, in our case we need to tell Savon, what is our namespace is, what is it's name (just to align it with WSDL) and prepend each tag's name with this namespace.
The correct code looks like this:
require 'savon'
access_token = "http%3a%2f%2fschemas.xmlsoap.org%2fws...CA9TEs%3d"
client = Savon.client(
wsdl: 'http://api.microsofttranslator.com/V2/soap.svc?wsdl',
namespace: 'http://api.microsofttranslator.com/V2',
namespace_identifier: :v2,
headers: {'Authorization' => "Bearer #{access_token}"},
)
params = {
'v2:text' => 'Это текст для перевода',
'v2:from' => 'ru',
'v2:to' => 'en',
'v2:contentType' => 'text/plain',
'v2:category' => 'general',
}
result = client.call(:translate, message: params)
puts result.body[:translate_response][:translate_result]
Any advices and corrections are welcome. Thanks.

How to use SOAP Request within AJAX call

This is my AJAX Application where i need to contact my Webservice running in server .
function sendRequest(method, url)
{
method == 'post';
{
http.open(method,url,true);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
This is the SOAP Request which i picked up from the SOAP UI , which was working fine
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.bayer.tata.com/" xmlns:tkw="http://tata.com/bayer" xmlns:chim="http://tata.com/chimera">
<soapenv:Header/>
<soapenv:Body>
<ser:strategy>
<!--Optional:-->
<request>
<xmlMessage>
<![CDATA[<test>or like this</test>]]>
</xmlMessage>
</request>
</ser:strategy>
</soapenv:Body>
</soapenv:Envelope>
Please tell me how can i use use this SOAP XML message within the sendRequest function .
I am using only plain Java Script AJAX ( Nothing like Jquery , DOJO , or any )
I think this Post can help you. But most of web servers allows you to invoke webservices using plain HTTP Post (without SOAP format in the body request) if the request doesn't need SOAP headers or other weird things.
An example in .NET and plain javaScript:
.NET web service
<System.Web.Services.WebService(Namespace:="http://JuntaEx/Agricultura/SegurInfo/GestorFirmaExterno/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class GestorFirmaExterno
Inherits System.Web.Services.WebService
<WebMethod(Description:="Retorna los documentos originales asociados a un identificador de firma pasado como parámetro.")> _
Public Function ObtenerDocumentoOriginal(ByVal idFirma As String) As DocumentoED()
//code
End Function
End Class
web.config:
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/> <!-- Allows plain HTTP Post -->
<add name="HttpSoap12"/>
<!-- Documentation enables the documentation/test pages -->
<add name="Documentation"/>
</protocols>
</webServices>
JavaScript request:
function crearRequest(url) {
if (window.XMLHttpRequest) {
peticion_http = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
peticion_http = new ActiveXObject('Microsoft.XMLHTTP');
}
peticion_http.open('POST', url, true); //sync
peticion_http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
return peticion_http;
}
peticion_http = crearRequest('http://localhost/wspuenteFirma/serviciopuente.asmx/ObtenerDocumentoOriginal');
peticion_http.onreadystatechange = obtenerDocHandler;
var query_string = 'IdFirma=' + encodeURIComponent(docId);
peticion_http.setRequestHeader('Content-Length', query_string.length);
peticion_http.send(query_string);
You send this request to the server:
POST /wsGestorFirmaExterno/GestorFirmaExterno.asmx/ObtenerDocumentoOriginal HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
idFirma=string
and recive this response from the server:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfDocumentoED xmlns="http://JuntaEx/Agricultura/SegurInfo/GestorFirmaExterno/">
<DocumentoED>
<hash>string</hash>
</DocumentoED>
<DocumentoED>
<hash>string</hash>
</DocumentoED>
</ArrayOfDocumentoED>
Parse it with javascript to obtain the info you need.
PS: You can configure the server and the browser request to send and recive JSON data instead of XML.
I hope it's helps.

Resources