EWS gSoap Connection with Impersonation - c++

all. I have next problem. I want to connect to mailbox with Impersonation rights. User Admin has Impersonation rights, and i know how to do it in C#.
I have next code:
ExchangeServiceBindingProxy *proxy = new ExchangeServiceBindingProxy(endpoint.c_str());
soap *pSoap = proxy->soap;
pSoap->userid = "Admin";
pSoap->passwd = "PASSWORD";
pSoap->ntlm_challenge = "";
pSoap->authrealm = "Ursa-Minor";
pSoap->ssl_flags = SOAP_SSL_NO_AUTHENTICATION;
pSoap->keep_alive = true;
soap_mode(pSoap,SOAP_IO_KEEPALIVE);
string smtp = "User1#no-such-email.com";
pSoap->header = new struct SOAP_ENV__Header();
pSoap->header->ns3__RequestServerVersion = new _ns3__RequestServerVersion();
pSoap->header->ns3__RequestServerVersion->Version = ns3__ExchangeVersionType__Exchange2007_USCORESP1;
if(!smtp.empty())
{
pSoap->header->ns3__ExchangeImpersonation = new ns3__ExchangeImpersonationType();
pSoap->header->ns3__ExchangeImpersonation->ConnectingSID = new ns3__ConnectingSIDType();
pSoap->header->ns3__ExchangeImpersonation->ConnectingSID->union_ConnectingSIDType.PrimarySmtpAddress = &smtp;
pSoap->header->ns3__ExchangeImpersonation->ConnectingSID->__union_ConnectingSIDType = 3;
}
As a resault i have this request:
POST /ews/Exchange.asmx HTTP/1.1
Host: 192.168.0.49
User-Agent: gSOAP/2.8
Content-Type: text/xml; charset=utf-8
Content-Length: 1093
Connection: keep-alive
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGoAAAAYABgAggAAABoAGgBAAAAACAAIAFoAAAAIAAgAYgAAAAAAAACaAAAABYKBAk4ATwAtAFMAVQBDAEgALQBFAE0AQQBJAEwASQB2AGEAbgBJAHYAYQBuAKEcAIkJWxEWBsuOv7MjtBpHLDWAL8JCTJ28+8Uotrb6QFrMa88HavXFTG1ddTR1VQ==
SOAPAction: "http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder"
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/messages">
<SOAP-ENV:Header>
<ns3:ExchangeImpersonation SOAP-ENV:mustUnderstand="1">
<ns3:ConnectingSID>
<ns3:PrimarySmtpAddress>User1#no-such-email.com</ns3:PrimarySmtpAddress>
</ns3:ConnectingSID>
</ns3:ExchangeImpersonation>
<ns3:RequestServerVersion SOAP-ENV:mustUnderstand="1" Version="Exchange2007_SP1"></ns3:RequestServerVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GetFolder xsi:type="ns1:GetFolderType"><ns1:FolderShape><ns3:BaseShape>AllProperties</ns3:BaseShape></ns1:FolderShape><ns1:FolderIds><ns3:DistinguishedFolderId Id="msgfolderroot" xsi:type="ns3:DistinguishedFolderIdType"></ns3:DistinguishedFolderId></ns1:FolderIds></ns1:GetFolder></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
It seems legit, but server response return error:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInternalServerError</faultcode>
<faultstring xml:lang="en-US">An internal server error occurred. The operation failed.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInternalServerError</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">An internal server error occurred. The operation failed.</e:Message>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
ns3:ExchangeImpersonation> !!! THERE IS SOMETHING WRONG
<ns3:RequestServerVersion SOAP-ENV:mustUnderstand="1" Version="Exchange2007_SP1"></ns3:RequestServerVersion>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetFolder xsi:type="ns1:GetFolderType">
<ns1:FolderShape><ns3:BaseShape>AllProperties</ns3:BaseShape></ns1:FolderShape>
<ns1:FolderIds>
<ns3:DistinguishedFolderId Id="msgfolderroot" xsi:type="ns3:DistinguishedFolderIdType"></ns3:DistinguishedFolderId>
</ns1:FolderIds>
</ns1:GetFolder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Response even doesn`t have well formed xml.
Well, i don`t know how to solve this problem at this moment.

To remove the mustunderstand attribute from the wsdl2h-generated source code declarations that produces the SOAP Header, use wsdl2h option -k.

This is an old question, but I had a little update on it: To those that may be experiencing issues with mustunderstand appearing due to using some gsoap plugin (for me it was with the wsse plugin, I know mustunderstand is part of that standard, but the service I am calling does not)
Anyway, to solve this I edited the header files in gsoap/import to remove the mustunderstand parts. This stopped the wsse header having mustunderstand included.

Related

How to fix "400 Bad Request" from the IP camera? Using ONVIF

I am writing a small client application that will poll the IP camera using the ONVIF protocol but Ifaced with the issue.
Need to use only C ++, without using gSOAP tools.
I use examples from this link Onvif programmers guide
Cameras that are not password protected and therefore do not require the generation of data for authorization, respond correctly.
The problem I faced is the forming of data for authorization.
When sending any request to the camera (for example, GetProfiles), the camera always responds with 400 errors.
Here is an example request:
POST /onvif/Media_service HTTP/1.1
Connection: keep-alive
Content-Length: 948
Content-Type: application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver10/media/wsdl/GetProfiles"
Host: 192.168.10.205
User-Agent: gSOAP/2.8
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>admin</Username>
<Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">M2IzYWYyOGE5OWE3ZDk3NGYzMGU1MzlkZWVhMDYyODMxMmU3NDIxMA==</Password>
<Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MTIzNDU2Nzg5</Nonce>
<Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2019-03-16T10:43:18Z</Created>
</UsernameToken>
</Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetProfiles xmlns="http://www.onvif.org/ver10/media/wsdl"/>
</s:Body>
</s:Envelope>
Here is an example of the camera response:
HTTP/1.1 400 Bad Request
Server: gSOAP/2.8
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1212
Connection: close
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope > // I skipped the listing of the namespace
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:Code>
<SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value>
<SOAP-ENV:Subcode>
<SOAP-ENV:Value>ter:NotAuthorized</SOAP-ENV:Value>
</SOAP-ENV:Subcode>
</SOAP-ENV:Code>
<SOAP-ENV:Reason>
<SOAP-ENV:Text xml:lang="en">Sender not Authorized</SOAP-ENV:Text>
</SOAP-ENV:Reason>
<SOAP-ENV:Detail>The action requested requires authorization and the sender is not authorized.</SOAP-ENV:Detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
According to point "6.1.1.3" from the documentation above, need to create a "Digest" as follows:
Digest = B64ENCODE( SHA1( B64DECODE( Nonce ) + Date + Password ) )
In my code, the functions B64DECODE, SHA1, and B64ENCODE work correctly, checked by comparing with various online generators.
I tried to set the Nonce parameter differently. So far, all to no avail.
As i guessthe error lies precisely in the work with the parameter that I send to the SHA1() function, but I can be wrong.
Can anyone say what could be the cause of the error?
I post not all the code, but only the part that is related to the formation of the necessary data.
I would be grateful for any help.
CODE:
// hardcoded nonce
char caNonceTest[20] = { 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38 };
caNonceTest[19] = '\0';
// Random generaterd nonce
//char caNonceTest[SHA_DIGEST_LENGTH];
//int nonceInt = rand();
//memset(caNonceTest, 1, SHA_DIGEST_LENGTH);
//memcpy(caNonceTest, &nonceInt, sizeof(nonceInt));
// Get data/time
string sDataUTC = currentISO8601TimeUTC();
// non-crypted password. Make function to get password from user
string sPass = "admin";
string sName = "default";
string sNonce(caNonceTest);
// temp string for SHA1
string sTempSumBin = (sNonce) + /*string2bin*/(sDataUTC)+ /*string2bin*/(sPass); // with string2bin it is also not working
unsigned char digest[SHA_DIGEST_LENGTH];
char cstr[sTempSumBin.size() + 1];
strcpy(cstr, sTempSumBin.c_str());
SHA1((unsigned char*)&cstr, strlen(cstr), (unsigned char*)&digest);
char cSHA1Pass[SHA_DIGEST_LENGTH * 2 + 1];
for (int i = 0; i < SHA_DIGEST_LENGTH; i++)
sprintf(&cSHA1Pass[i * 2], "%02x", (unsigned int)digest[i]);
printf("SHA1 string before : %s \n", cSHA1Pass);
string strTob64(cSHA1Pass);
string strFinishedPAss = base64_encode(strTOb64); // this is the final result of the password

How to format a SOAP request

I want to access an online program via the command line within a bash script. I've been told I can run a SOAP request in order to access the software. This is the request I've been told I can use.
POST /OnlineAnalysis/Service.asmx HTTP/1.1
Host: cydas.org
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.cydas.org/OnlineAnalysis/analyseKaryotype"
<?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>
<analyseKaryotype xmlns="http://www.cydas.org/OnlineAnalysis/">
<strKaryotype>string</strKaryotype>
</analyseKaryotype>
</soap:Body>
</soap:Envelope>
I've never run a SOAP request before but it looks like I'm able to use the curl command based on this question. I've tried to model my curl command according to the link I posted
curl -X POST -H "POST /OnlineAnalysis/Service.asmx HTTP/1.1" -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction: \"http://www.cydas.org/OnlineAnalysis/analyseKaryotype\"" -H "Host: cydas.org" --data-binary #request.xml
And am getting this output
<HTML>
<HEAD>
<TITLE>405 Method Not Allowed</TITLE>
<BASE href="/error_docs/"><!--[if lte IE 6]></BASE><![endif]-->
</HEAD>
<BODY>
<H1>Method Not Allowed</H1>
The HTTP verb used to access this page is not allowed.<P>
<HR>
<ADDRESS>
Web Server at cydas.org
</ADDRESS>
</BODY>
</HTML>
<!--
- Unfortunately, Microsoft has added a clever new
- "feature" to Internet Explorer. If the text of
...
These are the contents of my request.xml file 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>
<analyseKaryotype xmlns="http://www.cydas.org/OnlineAnalysis/">
<strKaryotype>46,XX,del(3)(p11)</strKaryotype>
</analyseKaryotype>
</soap:Body>
</soap:Envelope>
I'm not sure what the expected output is supposed to be yet because I can't run the program. I just want to get my SOAP request running properly.
try this:
curl -v "http://www.cydas.org/OnlineAnalysis/Service.asmx" -H "Content-Type: text/xml;charset=UTF-8" -H "SOAPAction: \"http://www.cydas.org/OnlineAnalysis/analyseKaryotype\"" -H "Connection: Keep-Alive" -H "Host: www.cydas.org" --data #request.xml
The server responded with the message: "The Karyotype del(3)(p11) is not valid:
Non-specified error in chromosome count element (del(3)(p11))"
Here's the complete response message:
<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>
<analyseKaryotypeResponse xmlns="http://www.cydas.org/OnlineAnalysis/">
<analyseKaryotypeResult>
<Original_ISCN_Formula>del(3)(p11)</Original_ISCN_Formula>
<IsPolyClonal>false</IsPolyClonal>
<IsValidKaryotype>false</IsValidKaryotype>
<Corrected_ISCN_Formula/>
<CloneSize>0</CloneSize>
<IsIncompleteKaryotype>false</IsIncompleteKaryotype>
<Ploidy>0</Ploidy>
<ErrorMessages>The Karyotype del(3)(p11) is not valid:
Non-specified error in chromosome count element (del(3)(p11))</ErrorMessages>
</analyseKaryotypeResult>
</analyseKaryotypeResponse>
</soap:Body>
</soap:Envelope>
cURL is a great tool, but if you want a nice gui you can try other tools like SoapUI or Postman for testing APIs. SoapUI is a standalone Java application and Postman is a plugin for Chrome. They're both free.

Adding SAMLSSO provider config to service provider using SOAP API

While I create the service provider and add the Inbound Authentication Config -> SAML2 Web SSO Configuration via Web UI of Identity Server admin panel everything works and I see the SAMLSSO provider in the expanded tab later.
Now I get stuck with creating the Service Provider and adding the SAMLSSO provider via API.
I am using the following services to do the work:
IdentityApplicationManagementService?wsdl - for creating service provider.
IdentitySAMLSSOConfigService?wsdl - for creating SAMLSSO provider.
I send the following request in order:
Firstly create the SAMLSSO provider:
POST /services/IdentitySAMLSSOConfigService.IdentitySAMLSSOConfigServiceHttpsSoap11Endpoint/ HTTP/1.1
Host: test.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.6.11-1ubuntu3.4
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:addRPServiceProvider"
Content-Length: 1228
Authorization: Basic *****
<?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/2001/XMLSchema-instance"
xmlns:ns1="http://dto.saml.sso.identity.carbon.wso2.org/xsd"
xmlns:ns2="http://org.apache.axis2/xsd">
<SOAP-ENV:Body>
<ns2:addRPServiceProvider>
<ns2:spDto>
<ns1:assertionConsumerUrl xsi:nil="true"/>
<ns1:assertionConsumerUrls>https://test.shib/Shibboleth.sso/SAML2/POST</ns1:assertionConsumerUrls>
<ns1:attributeConsumingServiceIndex xsi:nil="true"/>
<ns1:certAlias xsi:nil="true"/>
<ns1:defaultAssertionConsumerUrl>https://test.shib/Shibboleth.sso/SAML2/POST</ns1:defaultAssertionConsumerUrl>
<ns1:digestAlgorithmURI xsi:nil="true"/>
<ns1:idpInitSLOReturnToURLs xsi:nil="true"/>
<ns1:issuer>https://tesh.shib/shibboleth</ns1:issuer>
<ns1:loginPageURL xsi:nil="true"/>
<ns1:nameIDFormat xsi:nil="true"/>
<ns1:nameIdClaimUri xsi:nil="true"/>
<ns1:requestedAudiences xsi:nil="true"/>
<ns1:requestedClaims xsi:nil="true"/>
<ns1:requestedRecipients xsi:nil="true"/>
<ns1:signingAlgorithmURI xsi:nil="true"/>
<ns1:sloRequestURL xsi:nil="true"/>
<ns1:sloResponseURL xsi:nil="true"/>
</ns2:spDto>
</ns2:addRPServiceProvider>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Then I create the Service Provider with Inbound authentication config set with the SAMLSSO provider as mentioned here:
POST /services/IdentityApplicationManagementService.IdentityApplicationManagementServiceHttpsSoap11Endpoint/ HTTP/1.1
Host: test.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.6.11-1ubuntu3.4
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:createApplication"
Content-Length: 1934
Authorization: Basic ****
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://model.common.application.identity.carbon.wso2.org/xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://org.apache.axis2/xsd">
<SOAP-ENV:Body>
<ns2:createApplication>
<ns2:serviceProvider>
<ns1:applicationName>tect_com</ns1:applicationName>
<ns1:claimConfig xsi:nil="true"/>
<ns1:description>Test SP</ns1:description>
<ns1:inboundAuthenticationConfig>
<ns1:inboundAuthenticationRequestConfigs>
<ns1:friendlyName xsi:nil="true"/>
<ns1:inboundAuthKey>https://test.shib/shibboleth</ns1:inboundAuthKey>
<ns1:inboundAuthType>samlsso</ns1:inboundAuthType>
<ns1:properties xsi:nil="true"/>
</ns1:inboundAuthenticationRequestConfigs>
<ns1:inboundAuthenticationRequestConfigs>
<ns1:friendlyName xsi:nil="true"/>
<ns1:inboundAuthKey></ns1:inboundAuthKey>
<ns1:inboundAuthType>openid</ns1:inboundAuthType>
<ns1:properties xsi:nil="true"/>
</ns1:inboundAuthenticationRequestConfigs>
<ns1:inboundAuthenticationRequestConfigs>
<ns1:friendlyName xsi:nil="true"/>
<ns1:inboundAuthKey></ns1:inboundAuthKey>
<ns1:inboundAuthType>passivests</ns1:inboundAuthType>
<ns1:properties xsi:nil="true"/>
</ns1:inboundAuthenticationRequestConfigs>
</ns1:inboundAuthenticationConfig>
<ns1:inboundProvisioningConfig xsi:nil="true"/>
<ns1:localAndOutBoundAuthenticationConfig xsi:nil="true"/>
<ns1:outboundProvisioningConfig xsi:nil="true"/>
<ns1:owner>
<ns1:tenantDomain>user.com</ns1:tenantDomain>
<ns1:userName>user</ns1:userName>
<ns1:userStoreDomain xsi:nil="true"/>
</ns1:owner>
<ns1:permissionAndRoleConfig xsi:nil="true"/>
<ns1:requestPathAuthenticatorConfigs xsi:nil="true"/>
<ns1:saasApp>true</ns1:saasApp>
<ns1:spProperties xsi:nil="true"/>
</ns2:serviceProvider>
</ns2:createApplication>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Both request are accepted. I can see the Service Provider in Web UI, but the section with SAML Web SSO Configuration is empty.
If I try to authenticate with my new SP everything works.
If I try add the same SAML SSO Config via Web UI it gives me an error that it already exists.
The table SP_INBOUND_AUTH is empty while creating SAMLSSO Config using API. But if I create the SAML Configuration using Web UI, I can see the record in SP_INBOUND_AUTH table.
What am I missing?
When creating the Service provider, it should be done in two steps.
creating a service provider for the given application name and the description (createApplication).
update it with other configurations (updateApplication).
So in your case, createApplication should be invoked only with application name and description. Then you have to invoke updateApplication operation and configure its inbound authentication, etc.
[1] https://docs.wso2.com/display/IS510/Using+the+Service+Provider+API#UsingtheServiceProviderAPI-createApplication

How can I resolve "unexpected encoding style" using Savon Gem with Ruby on Rails

I am getting the following error when accessing a WSDL SOAP server:
{:error=>true, :message=>"Savon::SOAPFault: (env:Client) JAXRPCTIE01: caught exception while handling request: unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual="}
I went to soapclient.com to figure out what it's looking for.
Here is the error message I'm receiving.
Here is the code I'm using to connect to the SOAP client:
my_hash_of_stuff = {
zipcode: d_zip,
country: country
}
wsdl = 'http://my.yrc.com/dynamic/national/WebServices/YRCZipFinder_V1.wsdl'
client = Savon.client(wsdl: wsdl,
logger: Rails.logger,
log_level: :debug,
log: true,
pretty_print_xml: true,
env_namespace: :'soap-env',
strip_namespaces: true
)
response = client.call(:lookup_zip, message: my_hash_of_stuff)
print response.to_hash
Here's a copy of my log output so you can see what's happening.
This appears to be what the SOAP request should look like according to soapclient.com (if i'm understanding it correctly).
This is what I am sending.
I've been fighting with it all day and I'm sure it's probably a combination of my ignorance and something simple that i'm missing. Hopefully you guys might be able to help?
EDIT 05/25/2016:
So, looking at this again today, here's the log showing the request that savon is making:
HTTPI GET request to my.yrc.com (net_http)
SOAP request: http://my.yrc.com/dynamic/national/webservice/YRCZipFinder_V1
SOAPAction: "http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl/lookupCity", Content-Type: text/xml;charset=UTF-8, Content-Length: 417
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<tns:lookupCity>
<zipCode>84101</zipCode>
<country>USA</country>
</tns:lookupCity>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here's what a correct one looks like. I got this from the existing php app and tested it in Postman to verify that it works:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://my.yrc.com/national/WebServices/YRCZipFinderMessages_V1.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:lookupCity>
<lookupCityRequest xsi:type="ns2:YRCLookupCityRequest">
<zipCode xsi:type="xsd:string">84101</zipCode>
<country xsi:type="ns2:CountryCode">USA</country>
</lookupCityRequest>
</ns1:lookupCity>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
UPDATE:
After some more hacking, I have my request looking like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://my.yrc.com/national/WebServices/YRCZipFinderMessages_V1.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<tns:lookupCity lookupCityRequest="ns2:YRCLookupCityRequest">
<zipCode>84101</zipCode>
<country>USA</country>
</tns:lookupCity>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I need to get lookupCityRequest to move inside lookupCity instead of being an attribute of lookupCity, however. Testing it in Postman, that appears to be the only stumbling block left to hurdle.
You can use the special :attribute!symbol to assign additional attributes. That's a functionality from Nokogiri which Savon uses to build XML.
require 'savon'
my_hash_of_stuff =
{ zipcode: "99103",
country: 'US',
attributes!: { :country => { 'xsi:type' => 'ns2:YRCLookupCityRequest'},
:zipcode => { 'xsi:type' => 'ns2:YRCLookupCityRequest' }}
}
wsdl = 'http://my.yrc.com/dynamic/national/WebServices/YRCZipFinder_V1.wsdl'
client = Savon.client(wsdl: wsdl,
# logger: Rails.logger,
log_level: :debug,
log: true,
pretty_print_xml: true,
env_namespace: :'soap-env',
strip_namespaces: true
)
response = client.call(:lookup_zip,
message: my_hash_of_stuff)
print response.to_hash
If nothing works and you're desperate enough then you can still create your very own XML and use xml: instead of message:.

Internal Server Error in CreateItem operation of EWS

I'm using CreateItem Operation to save message in the Draft folder using EWS with gSOAP toolkit, but when i run the code I've response XML as follows:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">*</Action>
</s:Header>
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInternalServerError</faultcode>
<faultstring xml:lang="en-US">An internal server error occurred. The operation failed.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInternalServerError</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">An internal server error occurred. The operation failed.</e:Message>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
and in the terminal the fault which i've got is:
SOAP 1.1 fault: SOAP-ENV:MustUnderstand[no subcode]
"The data in element 'Action' must be understood but cannot be processed"
Detail: [no detail]
and there is no compile time error. If you need code, kindly let me know, I'll give that also. Please help me, I've tried a lot, but not find the solution, no matter I change in code, the response XML remains same.
Request XML is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ews="http://schemas.microsoft.com/exchange/services/2006/messages">
<SOAP-ENV:Body>
<ews:CreateItem xsi:type="ews:CreateItemType" MessageDisposition="SaveOnly"><ews:SavedItemFolderId xsi:type="ns1:TargetFolderIdType">
<ns1:DistinguishedFolderId Id="drafts" xsi:type="ns1:DistinguishedFolderIdType"></ns1:DistinguishedFolderId>
</ews:SavedItemFolderId>
<ews:Items xsi:type="ns1:NonEmptyArrayOfAllItemsType">
<ns1:Message xsi:type="ns1:MessageType">
<ns1:ItemClass xsi:type="ns1:ItemClassType">IPM.Note</ns1:ItemClass>
<ns1:Subject xsi:type="xsd:string">Project Action</ns1:Subject>
<ns1:Body BodyType="Text" xsi:type="ns1:BodyType">Priority - Update specification</ns1:Body>
<ns1:Sender xsi:type="ns1:SingleRecipientType">
<ns1:Mailbox xsi:type="ns1:EmailAddressType">
<ns1:EmailAddress xsi:type="ns1:NonEmptyStringType">markzuck93#live.com</ns1:EmailAddress>
</ns1:Mailbox>
</ns1:Sender>
<ns1:ToRecipients xsi:type="ns1:ArrayOfRecipientsType">
<ns1:Mailbox xsi:type="ns1:EmailAddressType">
<ns1:EmailAddress xsi:type="ns1:NonEmptyStringType">openuib#openuib.onmicrosoft.com</ns1:EmailAddress>
</ns1:Mailbox>
</ns1:ToRecipients>
</ns1:Message>
</ews:Items>
</ews:CreateItem>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I would suggest you get rid of all the xsi:type attributes eg how to remove xsi:type information from gSoap message?
Simplified your request should look like
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ews="http://schemas.microsoft.com/exchange/services/2006/messages">
<SOAP-ENV:Body>
<ews:CreateItem MessageDisposition="SaveOnly">
<ews:SavedItemFolderId>
<ns1:DistinguishedFolderId Id="drafts" />
</ews:SavedItemFolderId>
<ews:Items>
<ns1:Message>
<ns1:ItemClass>IPM.Note</ns1:ItemClass>
<ns1:Subject>Project Action</ns1:Subject>
</ns1:Message>
</ews:Items>
</ews:CreateItem>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Which works okay for me.
cheers
Glen
I recently explored the EWS api and found that a Sender tag causes the 500 response with the CreateItem request. Rather, you should be using the From tag.
<ns1:From xsi:type="ns1:SingleRecipientType">
<ns1:Mailbox xsi:type="ns1:EmailAddressType">
<ns1:EmailAddress xsi:type="ns1:NonEmptyStringType">markzuck93#live.com</ns1:EmailAddress>
</ns1:Mailbox>
</ns1:From>