How to set content-Type on WCF request - soap

My issue is that a testing app like Google Postman (awesome tool, found here) can send the message.
When I send the message it's always refused (the exact same message) because nonse is 'expired'.
So there must be something different about how I'm sending it...
There is... Content-Type is different, for one... but not sure if that's why...
I've seen some hints about accessing endpoint behaviours like:
var whb = client.ChannelFactory.Endpoint.Behaviors.Find<WebHttpBehavior>();
But that only allows me to choose between xml and json.
whb.AutomaticFormatSelectionEnabled = false;
whb.DefaultOutgoingRequestFormat = WebMessageFormat.Xml;
I have a wsdl:
http://caqh.org/SOAP/WSDL/CORERule2.2.0.wsdl
I need to call the WCF service's RealTimeTransaciton with headers that that are:
Content-Type: application/soap+xml;charset=UTF-8;
Currently, by default I suppose, the call includes headers;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
and Content-Type doesn't seem to be set.
So I tried to affect the headers of the request...
var addressHeaders = new List<AddressHeader> {
AddressHeader.CreateAddressHeader("Content-Type", "", "application/soap+xml;charset=UTF-8;"),
AddressHeader.CreateAddressHeader("Cache-Control", "", "no-cache"),
AddressHeader.CreateAddressHeader("Accept", "", "application/soap+xml;charset=UTF-8;")
};
var client = new CORETransactionsClient(binding, new EndpointAddress(new Uri(url),addressHeaders.ToArray()));
But to my surprise, the result of this is that these 'headers' are added within the soap Envelope headers, and not the headers for the transport!
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<Content-Type>application/soap+xml;charset=UTF-8;</Content-Type>
<Cache-Control>no-cache</Cache-Control>
<Accept>application/soap+xml;charset=UTF-8;</Accept>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
etc.... lol
My web.config service model:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CoreSoapBinding">
<textMessageEncoding messageVersion="Soap12" writeEncoding="UTF8" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://my_vendor_url_for_service_that_is_Axis2_based" binding="customBinding"
bindingConfiguration="CoreSoapBinding" contract="CoreRule.CORETransactions"
name="CoreSoapPort"
endpointConfiguration="">
</endpoint>
</client>
</system.serviceModel>
How I call:
var msg = Create270X12Message(requestReferenceId, senderId, receiverId, requestDateStr, productionCall, prettyOutput);
var envelope = new COREEnvelopeRealTimeRequest
{
CORERuleVersion = "2.2.0",
Payload = string.Format("<![CDATA[{0}]]>", Convert.ToBase64String(Encoding.UTF8.GetBytes(msg))),
PayloadID = requestReferenceId.ToString(),
PayloadType = CoreRule2PayloadType_270_5010,
ProcessingMode = CoreRule2ProcessingMode_270_5010,
ReceiverID = receiverId,
SenderID = senderId,
TimeStamp = requestDateStr
};
var client = CreateRealTimeOnlineProxy(urlMissouiri, username, password, requestDateStr);
var response = client.RealTimeTransaction(envelope);
How can I add my collection of headers to the request itself, instead of the SOAP Envelope headers?

Related

Call soap web-service in mobilefirst hybrid app

I'm attempting to call SOAP Web-Service in hybrid app. How should I form SOAP message correctly if the back-end service displays the next error in log:
Caused by: com.ibm.websphere.security.WSSecurityException: Exception
org.apache.axis2.AxisFault: CWWSS7509W: The received SOAP request
message is rejected becasue it does not correctly specify SOAP action
and WS-Addressing action while there is at least one PolicySet
attachment at operation level of the
TestServiceService.TestServicePort service. ocurred while running
action:
com.ibm.ws.wssecurity.handler.WSSecurityConsumerHandler$1#9b5addf6 at
com.ibm.ws.security.context.ContextImpl.runWith(ContextImpl.java:394)
at
com.ibm.ws.wssecurity.platform.websphere.auth.WSSContextImpl.runWith(WSSContextImpl.java:65)
... 35 more
This is content of js file in adapter
function getToken(){
var token = WL.Server.getActiveUser().attributes.LtpaToken;
var fulltoken = "LtpaToken2=" + token;
return fulltoken;
}
function callService(){
WL.Logger.warn("INSIDE callService "+getToken());
var path="checkauth/TestServiceService";
var request=
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:q0="http://provider.ws/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:callService />
</soapenv:Body>
</soapenv:Envelope>;
var input = {
method : 'post',
returnedContentType : 'xml',
path : path,
body: {
content: request.toString(),
contentType: 'text/xml; charset=utf-8',
},
headers: {"Cookie": getToken()}
};
var result= WL.Server.invokeHttp(input);
return result;
}
This is SOAP Envelope which was displayed via TCP/IP Monitor:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<s:Security xmlns:s="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:w2="http://www.ibm.com/websphere/appserver/tokentype" soapenv:mustUnderstand="1">
<u:Timestamp>
<u:Created>2015-08-10T13:18:56.644Z</u:Created>
</u:Timestamp>
<s:BinarySecurityToken ValueType="w2:LTPAv2" u:Id="ltpa_20">dt8G5gZ9PpZ/Ea5oXr6EQd8dpmfXKiqeXiShPlpSWntK59hUzyoDNX9TKq1nFLfxUEJyJdjMxoG7EVxw8Q1zhyZdYhTXnsMkNVqScvSsPpX7ln/ad+/WAHqaaFymD8XtVEsjOlezQDarPaUmnKAQRUSrLkRnL5B1MoCclTe129Oojg8o+hACgDKjuvPnvL8jaf45wNiou6Il5ZOayBcoHpNehI7i2hADa4fTKzX/T69OPnsZOyWYrNosdezNd24b61vs85k2YK26rLTp5dkEp8f3mwKZBwOOK4z1wQdiAXJf6kQvzR22SfFitbJA5MStlBcovHAvB5T+J5Ip80/kI5BPa2ogoufd9HZAdKTNII8cHpHBN2Ub/+atzg1L7EhIWuzO1BPI62KoU/hPqAHn3uGCGrbIILesKx0TPvlgmU4Bg54H9prC0I8hgXbO1HLuz4M5DNE5ASFbH0W3LJ/UU7BGXJs6iJmfAfJtQ+ip5ZFHlLItZA+ca2LkVWmyD/xKVxyxHE1uDz8zV/CfV9Km0T+8FTA0Cfi/PIb5KiAagdrmqtw6GuJDbSCsC3sdh21G/cA3Y0p/f+rhDw8m/e17y1cEuq9HOBharwn7ET3wO30V4D4rGoLhd4QsN6X1z89gZmZVaI6J9urpPAEiSndmyQ==</s:BinarySecurityToken>
</s:Security>
<wsa:To>http://X.X.X.X:9082/checkauth/TestServiceService</wsa:To>
<wsa:MessageID>urn:uuid:5d1f8656-5550-40d2-9f39-c58f57279489</wsa:MessageID>
<wsa:Action>http://provider.ws/TestServiceDelegate/callServiceRequest</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<ns2:callService xmlns:ns2="http://provider.ws/"/>
</soapenv:Body></soapenv:Envelope>
The body consists of a single line, and this makes the scenario a peculiar one, as well as raises a question is this is meant to work at all.
I can suggest two things:
You can attempt to parse your WSDL file with the SOAPUI application; it should show you how the SOAP envelope is supposed to look like
Use the Service Discovery feature in MobileFirst Studio that can generate the adapter for you with a ready SOAP envelope. Read more how to use this feature, here: http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.0.0/com.ibm.worklight.dev.doc/dev/c_using_service_discovery_wizard_to_explore_backend-services.html

Accessing SOAP services with Google Apps Script

I'm trying to use Google Apps Scripts to call a SOAP service call, and I've been trying to tinker with a number of ways to get a response; however, I keep getting an error. I've defaulted to trying to send an exact copy of a message stored in my spreadsheet that I know works through another service... still no luck. Here's the Apps Script Code:
function getVesselSummaryXMLStringFromName() {
var wsdl = SoapService.wsdl("http://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL");
Logger.log(wsdl.getServiceNames());
var uscgService = wsdl.getPSIXData();
var sheet = SpreadsheetApp.getActiveSheet();
//Get working SOAP message
var envelope = sheet.getRange("D1:D1").getValues();
Logger.log(envelope);
var result = uscgService.getenvelope;
Logger.log(result);
}
The SOAP message I'm sending that works through http://www.soapclient.com/soapclient is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://cgmix.uscg.mil" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><SOAP-ENV:Body><tns:getVesselSummaryXMLString xmlns:tns="http://cgmix.uscg.mil"><tns:VesselID></tns:VesselID><tns:VesselID></tns:VesselID><tns:VesselName>Atlantic Salvor</tns:VesselName><tns:VesselName></tns:VesselName><tns:CallSign></tns:CallSign><tns:CallSign></tns:CallSign><tns:VIN></tns:VIN><tns:VIN></tns:VIN><tns:HullNum></tns:HullNum><tns:HullNum></tns:HullNum><tns:Flag></tns:Flag><tns:Flag></tns:Flag><tns:Service></tns:Service><tns:Service></tns:Service><tns:BuildYear></tns:BuildYear><tns:BuildYear></tns:BuildYear></tns:getVesselSummaryXMLString></SOAP-ENV:Body></SOAP-ENV:Envelope>
The following code returns an answer, so maybe you can help.
...
var url = 'http://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL';
var wsdl = SoapService.wsdl(url);
var servicePSIXData = wsdl.getPSIXData();
var params = Xml.element('getVesselSummaryXMLString', [
Xml.attribute('xmlns', 'http://cgmix.uscg.mil'),
Xml.element('VesselID', ['']),
Xml.element('VesselName', ['Atlantic Salvor']),
Xml.element('CallSign', ['']),
Xml.element('VIN', ['']),
Xml.element('HullNum', ['']),
Xml.element('Flag', ['']),
Xml.element('Service', ['']),
Xml.element('BuildYear', [''])
]);
var result = servicePSIXData.getVesselSummaryXMLString(params);
Logger.log(result.toXmlString());
...
UPDATE
Both Xml Services and Soap Services are considered deprecated.

Alfresco REST API:Data Size Limit?

I am developing REST based webservices in alfresco for data transfer & want to know what is the maximum amount of data i can send/get thru REST protocol?
Any reference would be very helpful.
Regards.
The max amount of data is as large as 2147000000. That's why if your data is large enough it is advisable to stream it to post to your REST service. Here's an example.
Sender/ Uploader Application or Client
var sb = new StringBuilder();
sb.Append("Just test data. You can send large one also");
var postData = sb.ToString();
var url = "REST Post method example http://localhost:2520/DataServices/TestPost";
var memoryStream = new MemoryStream();
var dataContractSerializer = new DataContractSerializer(typeof(string));
dataContractSerializer.WriteObject(memoryStream, postData);
var xmlData = Encoding.UTF8.GetString(memoryStream.ToArray(), 0, (int)memoryStream.Length);
var client = new WebClient();
client.UploadStringAsync(new Uri(url), "POST", "");
client.Headers["Content-Type"] = "text/xml";
client.UploadStringCompleted += (s, ea) =>
{
if (ea.Error != null) Console.WriteLine("An error has occured while processing your request");
var doc = XDocument.Parse(ea.Result);
if (doc.Root != null) Console.WriteLine(doc.Root.Value);
if (doc.Root != null && doc.Root.Value.Contains("1"))
{
string test = "test";
}
};
REST Service method
[WebInvoke(UriTemplate = "TestPost", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Xml)]
public string Publish(string market,string sportId, Stream streamdata)
{
var reader = new StreamReader(streamdata);
var res = reader.ReadToEnd();
reader.Close();
reader.Dispose();
}
Don't forget to put the following configuration settings on your REST Service config file if you don't have this it will throw you an error
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2147000000" maxQueryStringLength="2097151" maxUrlLength="2097151"/>
</system.web>
<system.webServer>
........
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147000000" maxBufferPoolSize="2147000000" maxBufferSize="2147000000"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>

How to get OMElement by name in mediate?

I have a response message like this:
<message>
<header>
<TransactionID>1</TransactionID>
<Timestamp>2012-05-22 10:10:36</Timestamp>
<OpCode>BOSS_DELETE_USER_SME.CD</OpCode>
<MsgType>RESP</MsgType>
<ReturnCode>1016</ReturnCode>
<ErrorMessage>uif return error message!</ErrorMessage>
</header>
</message>
I need convert RetuenCode "1016" to "0" in extension class. How to get OMElement "ReturnCode" in mediate? My code is failed.
SOAPEnvelope envelope = context.getEnvelope();
SOAPBody soapBody = envelope.getBody();
QName ReturnCode = new QName(null, "ReturnCode");
OMElement response = soapBody.getFirstChildWithName(ReturnCode);
The section
<header>
Is it inside the SOAP body ? if that is the case first you need to get the Header element from SOAP body and then get the first child with name ReturnCode from that element.
cheers,
Charith

400 Bad Request : Consuming WCF basicHttpBinding (Soap) using JScript/VBScript

var oXMLDoc, oXMLHttp, soapRequest, soapResponse;
oXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHttp.open("POST", "http://nerdbox/HelloService.svc", false);
// Add HTTP headers
oXMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXMLHttp.setRequestHeader("SOAPAction", "http://tempuri.org/IHelloService/SayHello");
// Form the message
soapRequest = '<?xml version="1.0" encoding="utf-16"?><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><SayHello xmlns="http://tempuri.org/"><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>';
WScript.Echo("Request : " + soapRequest);
oXMLHttp.send(soapRequest);
soapResponse = oXMLHttp.responseXML.xml;
WScript.Echo("Respose : " + soapResponse);
Whats wrong with this JScript? why am I getting 400 Bad Request. I read similar threads in stackoverflow .. some say its soap message formatting problem.
This is what the message looks like if I take it from fiddler.
Try changing your action from IHelloService to HelloService.
And let me ask you, why are you doing it the hard way. Just add a webHttpBinding and use JSON.
See a very easy example here.
I had to change your code to the following to get it to run in VBSEdit...then I (obviously) got the error about it not being able to find the resource...but change your code to this and see if it makes a difference?
Dim oXMLDoc, oXMLHttp, soapRequest, soapResponse
Set oXMLHttp = CreateObject("Microsoft.XMLHTTP")
oXMLHttp.open "POST", "http://nerdbox/HelloService.svc", False
'// Add HTTP headers
oXMLHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXMLHttp.setRequestHeader "SOAPAction", "http://tempuri.org/IHelloService/SayHello"
'// Form the message
soapRequest = "<?xml version=""1.0"" encoding=""utf-16""?><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><SayHello xmlns=""http://tempuri.org/""><name>Zuhaib</name></SayHello></soap:Body></soap:Envelope>"
WScript.Echo "Request : " + soapRequest
oXMLHttp.send soapRequest
soapResponse = oXMLHttp.responseXML.xml
WScript.Echo "Respose : " + soapResponse