Junit for SOAP service call - soap

I have the below client side code to invoke a SOAP based webservice.
I want to write a junit for the below code which will not invoke the actual web service but use some mock calls.
URL url = null;
try {
url = new URL("someendpoint");
QName qname = new QName("someURI", "someservicename");
Service service = Service.create(url, qname);
forData1PortType = service.getPort(ForData1PortType.class);
ForReferenceDataType req2= buildACompleteForDataRequest();
ResponseGetForDataType referenceData1=null;
BindingProvider bp = (BindingProvider) forData1PortType;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "someendpoint");
Client client = ClientProxy.getClient(forData1PortType);
referenceData1 = forData1PortType.getReferenceData1(req2);
}

Related

Dynamics 365 Plugin call External REST API - SSL/TSL could not create channel issue

I have a task to call the external REST API to get data from third party application.
In that, i have created a C# Console application for tried this and it is working fine and i can get the data from thirty party application via REST API.
The same code used to tried in Dynamics Custom workflow\Plugin, i have got a error below. Please give your valuable suggestion on this.
"System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel."
Note: The below options are tried but no luck.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
ServicePointManager.Expect100Continue = true;
Thanks,
Vasanth
It is not clear how you are calling external API from D365 Plugin.
// Call external API
static async Task<bool> CallExternalAPI(Guid beziehungId)
{
bool status = false;
HttpClient apiClient = new HttpClient();
apiClient.DefaultRequestHeaders.Accept.Clear();
apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string url = #"https://reqres.in/api/users?page=2";
HttpResponseMessage response = await apiClient.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
return status;
}
If your problem with SSL/TLS secure channel you can use WebClient.
// Could not create SSL/TLS secure channel.
// Use (SecurityProtocolType)3072
using (WebClient client = new WebClient())
{
client.Headers.Add(HttpRequestHeader.UserAgent, "AvoidError");
ServicePointManager.Expect100Continue = true;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
htmlCode = client.DownloadString("MY LINK");
//passing the URL again to function from which to extract the content and compare from above content.
strNewCompanyCode = client.DownloadString("MY LINK");
}

Sustainsys.Saml2.HttpModule Service Provider initiated sample code

Is there sample c# code (not web.config) to do a Service Provide initiated call and also receiving the response from the Identity provider for HttpModule? I have a web forms application. The code below has mixed MVC stuff (which doesn't work). Thanks in advance.
var idp = Options.FromConfiguration.IdentityProviders.Default;
var defaultDestination = idp.SingleSignOnServiceUrl;
string UriString = "http://localhost:49826/sso";
Sustainsys.Saml2.WebSso.HttpRequestData request = ToHttpRequestData(context);
var result = new SignInCommand().Run(request, Options.FromConfiguration);
var httpResponseBase = new HttpResponseWrapper(context.Response);
result.ApplyCookies(httpResponseBase, false);

Docusign Soap API returns Unspecified Error

I have been trying to send a docusign envelope from Salesforce using the docusign SOAP API. I am using the CreateEnvelopeFromTemplates method of the Docusign API, I have a functional template created in my docusign sandbox, but everytime I send the request I get an Unspecified Error in my response. Below is the code the I am using
wwwDocusignNetApi30.EnvelopeInformation envelope = new wwwDocusignNetApi30.EnvelopeInformation();
envelope.Subject = 'Envelope Subject' ;
envelope.EmailBlurb = 'Email Blurb';
envelope.AccountId = '********-****-****-****-************';
//use custom field to store the id of the record that initiated the transaction
envelope.CustomFields = new wwwDocusignNetApi30.ArrayOfCustomField();
envelope.CustomFields.CustomField = new wwwDocusignNetApi30.CustomField[2];
wwwDocusignNetApi30.CustomField myCustomField = new wwwDocusignNetApi30.CustomField();
myCustomField.Name = 'DSFSSourceObjectId';
myCustomField.Value = '0012600000PQn9g';
myCustomField.Show = 'false';
myCustomField.Required = 'false';
myCustomField.CustomFieldType = 'Text';
envelope.CustomFields.CustomField.add(myCustomField);
wwwDocusignNetApi30.ArrayOfTemplateReference templateArray = new wwwDocusignNetApi30.ArrayOfTemplateReference();
templateArray.TemplateReference = new wwwDocusignNetApi30.TemplateReference[2];
wwwDocusignNetApi30.TemplateReference templat = new wwwDocusignNetApi30.TemplateReference();// TemplateReferences
templat.Template = '********-****-****-****-************';
templat.TemplateLocation = 'Server';
wwwDocusignNetApi30.ArrayOfRecipient1 recArray = new wwwDocusignNetApi30.ArrayOfRecipient1();
recArray.Recipient = new wwwDocusignNetApi30.Recipient[2];
wwwDocusignNetApi30.Recipient recipient = new wwwDocusignNetApi30.Recipient();
recipient.ID = 100987;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 2;
recipient.Email = 'example#example.com';
recipient.UserName = 'Test';
recArray.Recipient.add(recipient);
wwwDocusignNetApi30.TemplateReferenceRoleAssignment trra = new wwwDocusignNetApi30.TemplateReferenceRoleAssignment();
trra.RoleName='Signer 1';
trra.RecipientID = recipient.ID;
wwwDocusignNetApi30.ArrayOfTemplateReferenceRoleAssignment roleArray = new wwwDocusignNetApi30.ArrayOfTemplateReferenceRoleAssignment();
roleArray.RoleAssignment = new wwwDocusignNetApi30.TemplateReferenceRoleAssignment[1];
roleArray.RoleAssignment.add(trra);
templat.RoleAssignments = new wwwDocusignNetApi30.ArrayOfTemplateReferenceRoleAssignment();
templat.RoleAssignments = (roleArray);
templateArray.TemplateReference.add(templat);
String auth = '<DocuSignCredentials><Username>********-****-****-****-************</Username><Password>PASSWORD</Password><IntegratorKey>********-****-****-****-************</IntegratorKey></DocuSignCredentials>';
wwwDocusignNetApi30.APIServiceSoap service = new wwwDocusignNetApi30.APIServiceSoap();
service.inputHttpHeaders_x = new Map<String, String>();
service.inputHttpHeaders_x.put('X-DocuSign-Authentication',auth);
service.CreateEnvelopeFromTemplates(templateArray,recArray,envelope,true);
Below is the response I receive:
System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Unspecified_Error faultcode=soap:Server faultactor=https://demo.docusign.net/api/3.0/dsapi.asmx
Since the error message is vague, I am not able to debug the issue. Any help is appreciated.
I suggest that you start with a simpler request. Look at the recipes on github.com/docusign that start with sfdc
Get the simpler request working, then add features to get it to your needs.
One thing I did notice was that you are not giving a routing order of 1 to your only recipient. But that's probably OK.
I'm not sure that your template reference is correct since you should not be using composite templates for a simple template reference. Unfortunately I don't have a lot of experience with the soap api. HTH.

ServiceStack on server and .NET Compact Framework client

I created my server and clients (MonoDroid and Windows) with ServiceStack, everything works very well, but now I need to consume the data from the server with a mobile client with Compact Framework F3.5.
I can access it as SOAP webservice, but I would prefer to go through REST, and use a framework to simplify things, just like the ServiceStack client (that as RestSharp is not compatible with the Compact Framework).
Do you know of something compatible with CF3.5 that lets me connect with a ServiceStack server in an easy way as
var client = new JsonServiceClient("http://192.168.0.87:82");
HelloResponse response = client.Get(new Hello { Name = "World!" });
UPDATE:
I managed to get the response with HTTPWebRequest and deserialize my HelloResponse object with an old JSON.Net version that supports the .NET Compact Framework.
The only thing that I'm missing is how to serialize my hypothetical HelloReq object and pass it to the HttpWebRequest, any hint? (without having to manually create the route as below)
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://192.168.0.87:82/Hello/test?format=json");
req.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream respStream = resp.GetResponseStream();
string resps;
using (var reader = new StreamReader(respStream, Encoding.UTF8))
{
resps = reader.ReadToEnd();
}
respStream.Close();
JsonTextReader jreader = new JsonTextReader(new StringReader(resps));
JsonSerializer serializer = new JsonSerializer();
HelloResponse p = serializer.Deserialize<HelloResponse>(jreader);
Thanks!
Request created:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://192.168.0.87:82/json/syncreply/Hello");
req.ContentType = "text/json";
req.Method = "POST";
req.ContentLength = json.Length;
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
{
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}

How to call a GwtServiceImpl Servlet from external application?

I have developed a Gwt application and need now to call its remote service implementation
from another java application. Is there a method that given a List of Java Objects can transform them in a format suitable for invoking the get service servlet?something like:
myObject = .......
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"http://localhost:8080/ppp//org.yournamehere.Main/gwtservice");
String serialized = <somelibrary.serialize>(myObject);
StringEntity input = new StringEntity(serialize);
input.setContentType("text/x-gwt-rpc; charset=UTF-8");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
Although, I haven't tried it the following link seems to be what you are looking for
http://googlewebtoolkit.blogspot.com/2010/07/gwtrpccommlayer-extending-gwt-rpc-to-do.html