In MVC, Workflow Service not working wihout any error - model-view-controller

I am calling WF as a service (hosted as a Service Reference in client)from my MVC web client. After publish when I deploy and hosting WebClient and WF service in my local machine IIS it is working and workflow calls all the defined activity. But when I am deploying same build on Production Server (Windows Server 2012) then seems WF service not getting called without any error. Please find below code
[HttpPost]
public ActionResult NewFeed(FeedProcessViewmodel fpmodel)
{
//some database object creation and saving
waiting to save the data into database and use the generated request id
sBL.SaveFeedDetailAsync(m_objMasterSnapShot, m_objMasterFeed, m_objFeedDetail);
//calling windows workflow service
InputRequest objInputRequest = new InputRequest { RequestId = "requestid" };
ServiceClient objServiceClient = new ServiceClient();
OutputResponse outputResponse = objServiceClient.SubmitRequest(objInputRequest);
if (!outputResponse.Success)
{
oDic.Add("Error", outputResponse.Message);
jrResult.Data = oDic;
throw new Exception(outputResponse.Message);
}
else
{
//CALLING THIS LINE AFTER OUTRESPONSE LINE EXECUTION
// BUT ALL THE ACTIVITY WITHING WORKFLOW NOT EXECUTED
oDic.Add("Ok", outputResponse.Message);
jrResult.Data = oDic;
}
}
Any help
Thanks

Its too late to reply to this post as I actually forgot to add an update for this.
The reason for above issue was at InputRequest class constructor.
InputRequest objInputRequest = new InputRequest { RequestId = "requestid" };
Had code which was returning null and because InputRequest class had try-catch block, actual error was suppressed and not propagated to calling place.

Related

CRM 2016 OrganizationServiceProxy.EnableProxyTypes seems to hang

We're currently changing the architecture of our back end systems and we've discovered that we need to enable proxy types for use in CodeActivities for Workflows, using the OrganizationServiceProxy.EnableProxyTypes method.
However, whenever I include this method call it makes the Workflow run extremely slow before eventually failing.
Here is the code we use to call the method:
var service = serviceFactory.CreateOrganizationService(context.UserId);
if (service is OrganizationService)
{
tracingService.Trace("Enabling proxy types");
((OrganizationServiceProxy)((OrganizationService)service).InnerService).EnableProxyTypes(assembly);
tracingService.Trace("Proxy types enabled");
}
Any ideas?
Thanks
I've never had to pass an assembly in as a parameter to EnableProxyTypes. Did you try it without passing the assembly?
Also, there's another way to enable proxy types by adding to the Behaviors collection. Here's an example:
public static IOrganizationService GetOrganizationService(Guid userId)
{
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
Uri homeRealmUri = null;
using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(new Uri(GetOrganizationUri()),
homeRealmUri, credentials, null))
{
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
_serviceProxy.CallerId = userId;
IOrganizationService _service = (IOrganizationService)_serviceProxy;
return _service;
}
}

Internal Server Error (500) when creating a document in DocumentDB from data passed on from Console Application to ASP.NET WebAPI

I have an ASP.NET WebAPI Controller which creates a document in Azure DocumentDB from the data passed on to its POST method from a Console app. The return type of the POST method is HttpResponseMessage which returns a status code for OK (i.e. 200) when the document has been successfully created.
The document gets created successfully from the WebAPI and the status code 200 is returned too. But somewhere then it goes wrong (which I can't figure out where and why) and the status code that my Console app receives after the successful POST is 500 - an Internal Server Error occurred.
public HttpResponseMessage Post([FromBody]GPSDataVM data)
{
if (KeyRepository.IsValid(data.Key))
{
// Creates a document in DocumentDB by calling an async method CreateLiveDataDocument(data);
return new HttpResponseMessage(HttpStatusCode.OK);
}
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
Can anyone help me out with the situation? Thanks in advance ..
I found an answer to my problem from the following address:
Web Api + HttpClient: An asynchronous module or handler completed while an asynchronous operation was still pending
I changed the definition to my WebAPI Controller to:
public **async Task<HttpResponseMessage>** Post([FromBody]GPSDataVM data) {
if (KeyRepository.IsValid(data.Key))
{
// Creates a document in DocumentDB by calling an async method
**// Code for CreateLiveDataDocument(data)**
return new HttpResponseMessage(HttpStatusCode.OK);
}
return new HttpResponseMessage(HttpStatusCode.Unauthorized); }

WebApi Odata Windows Store App EndSaveChanges exception

I am trying to create a Windows Store App using a WebApi Odata controller. After some effort I have all the Get requests working, I am now moving onto the CRUD methods, and am getting the following Exception on the EndSaveChanges of the Data Service Context.
<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code />
<m:message xml:lang="en-US">No HTTP resource was found that matches the request URI 'http://localhost:56317/odata/ESFClients(guid'f04ad636-f896-4de4-816c-388106cd39ce')'.</m:message>
<m:innererror>
<m:message>No routing convention was found to select an action for the OData path with template '~/entityset/key'.</m:message>
<m:type></m:type>
<m:stacktrace></m:stacktrace>
</m:innererror>
</m:error>
Now I think this is a bug in WebApi from this http://aspnetwebstack.codeplex.com/workitem/822 and its hiding the actual error. To make sure it wasn't my Odata Endpoint I created a quick console app to get an entry, update it and Patch it back, which worked all ok. My WebApi Odata Controller derives from ODataController with
public HttpResponseMessage Patch([FromODataUri] Guid key, Delta<ESFClient> patch)
As the method.
In my windows application I have a extension method on the DataServiceContext for the Save Changes.
public static async Task<DataServiceResponse> SaveChangesAsync(this DataServiceContext context, SaveChangesOptions options)
{
var queryTask = Task.Factory.FromAsync<DataServiceResponse>(context.BeginSaveChanges(options, null, null),
queryAsyncResult =>
{
var results = context.EndSaveChanges(queryAsyncResult);
return results;
});
return await queryTask;
}
And calling the update like so from a blank Windows Store XAML page.
public async Task UpdateWeekNo()
{
var container = new ESFOdataService.Container(new Uri("http://localhost:56317/odata/"));
var clients = (DataServiceQuery<ESFClient>)from p in container.ESFClients where p.UserID == new Guid("f04ad636-f896-4de4-816c-388106cd39ce") select p;
var result = await clients.ExecuteAsync();
var updatedClient = result.Single();
if (updatedClient != null)
{
updatedClient.WeekNo = 19;
container.UpdateObject(updatedClient);
await container.SaveChangesAsync(SaveChangesOptions.PatchOnUpdate); // Use PATCH not MERGE.
}
}
So does anyone come across the same issue, or know how I can find out the actual error. One interesting point is that if I debug the controller while running the Windows App, the patch method does not get called.
Ok, so I have finally solved this. Just a recap for those who could experience the same issue. I have an Odata WebApi controller, Windows 8 Store Application using WCF Client Library, with the reference created from Add Service Reference. When trying to update (patch) a record an exception was being thrown at the EndSaveChanges. This is because for some reason Post Tunneling is enabled by default on my context. Setting this to false allowed everything to work.
Context.UsePostTunneling = false;
Context.IgnoreResourceNotFoundException = true;

Dynamics AX 2009 : can't save new Customer via webservice using AxdCustomer Class

CustomerService CustService = new CustomerService();
try
{
CustService.Credentials = new NetworkCredential("xxx", "xxx", "xxx");
AxdCustomer customer = new AxdCustomer();
AxdEntity_CustTable[] table = new AxdEntity_CustTable[1];
AxdEntity_CustTable test = new AxdEntity_CustTable();
test.AccountNum = TextBox1.Text;
test.Name = TextBox1.Text;
test.CustGroup = DropDownList1.SelectedItem.Value;
table[0] = test;
customer.CustTable = table;
CustService.create(customer);
}
catch (Exception ex)
{
err.Visible = true;
lblerr.Text = ex.Message;
}
I am new to Dynamics AX. I'm trying to create a customer which is actually created by consuming a webservice from the web . the above code snippet is the code for that, but it's giving an exception as :
Request Failed. See the Exception Log for details.
I'm not even getting the actual reason why it's not getting created. How to create a customer in dynamics AX 2009 sp1?
Note: CustService is the CustomerService object for the class in CustomerSvc namespace (it is the webservice reference to the CustomerService webservice in Dynamics).
Have a look at the event log in the server where there webservice and the AOS is hosted on.
You may get half a clue from there.
Also have a look at the exception log in AX which you can get from
Basic -> Periodic -> Application Integration framework -> Exceptions
Once you get the error details then you may figure out the problem otherwise post them here and I an have a further look at what the problem might be.

Windows Service Hosting WCF Objects over SSL (https) - Custom JSON Error Handling Doesn't Work

I will first show the code that works in a non-ssl (http) environment. This code uses a custom json error handler, and all errors thrown, do get bubbled up to the client javascript (ajax).
// Create webservice endpoint
WebHttpBinding binding = new WebHttpBinding();
ServiceEndpoint serviceEndPoint = new ServiceEndpoint(ContractDescription.GetContract(Type.GetType(svcHost.serviceContract + ", " + svcHost.assemblyName)), binding, new EndpointAddress(svcHost.hostUrl));
// Add exception handler
serviceEndPoint.Behaviors.Add(new FaultingWebHttpBehavior());
// Create host and add webservice endpoint
WebServiceHost webServiceHost = new WebServiceHost(svcHost.obj, new Uri(svcHost.hostUrl));
webServiceHost.Description.Endpoints.Add(serviceEndPoint);
webServiceHost.Open();
I'll also show you what the FaultingWebHttpBehavior class looks like:
public class FaultingWebHttpBehavior : WebHttpBehavior
{
public FaultingWebHttpBehavior()
{
}
protected override void AddServerErrorHandlers(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.ChannelDispatcher.ErrorHandlers.Clear();
endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new ErrorHandler());
}
public class ErrorHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
return true;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
// Build an object to return a json serialized exception
GeneralFault generalFault = new GeneralFault();
generalFault.BaseType = "Exception";
generalFault.Type = error.GetType().ToString();
generalFault.Message = error.Message;
// Create the fault object to return to the client
fault = Message.CreateMessage(version, "", generalFault, new DataContractJsonSerializer(typeof(GeneralFault)));
WebBodyFormatMessageProperty wbf = new WebBodyFormatMessageProperty(WebContentFormat.Json);
fault.Properties.Add(WebBodyFormatMessageProperty.Name, wbf);
}
}
}
[DataContract]
public class GeneralFault
{
[DataMember]
public string BaseType;
[DataMember]
public string Type;
[DataMember]
public string Message;
}
The AddServerErrorHandlers() method gets called automatically, once webServiceHost.Open() gets called. This sets up the custom json error handler, and life is good :-)
The problem comes, when we switch to and SSL (https) environment. I'll now show you endpoint creation code for SSL:
// Create webservice endpoint
WebHttpBinding binding = new WebHttpBinding();
ServiceEndpoint serviceEndPoint = new ServiceEndpoint(ContractDescription.GetContract(Type.GetType(svcHost.serviceContract + ", " + svcHost.assemblyName)), binding, new EndpointAddress(svcHost.hostUrl));
// This exception handler code below (FaultingWebHttpBehavior) doesn't work with SSL communication for some reason, need to resarch...
// Add exception handler
serviceEndPoint.Behaviors.Add(new FaultingWebHttpBehavior());
//Add Https Endpoint
WebServiceHost webServiceHost = new WebServiceHost(svcHost.obj, new Uri(svcHost.hostUrl));
binding.Security.Mode = WebHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
webServiceHost.AddServiceEndpoint(svcHost.serviceContract, binding, string.Empty);
Now, with this SSL endpoint code, the service starts up correctly, and wcf hosted objects can be communicated with just fine via client javascript. However, the custom error handler doesn't work. The reason is, the AddServerErrorHandlers() method never gets called when webServiceHost.Open() is run.
So, can anyone tell me what is wrong with this picture? And why, is AddServerErrorHandlers() not getting called automatically, like it does when I'm using non-ssl endpoints?
Thanks!
I will refer you to MSDN docs
If the Transport value is specified by
the
WebHttpBinding(WebHttpSecurityMode),
then the settings provided by the
Transport property become effective
for the service endpoint. The value of
WebHttpSecurityMode can only be set in
the WebHttpBinding constructor that
takes it as an explicit parameter and
its value cannot be set again after
the binding instance is created.
see : http://msdn.microsoft.com/en-us/library/bb348328.aspx
So you need to pass this value
binding.Security.Mode = WebHttpSecurityMode.Transport;
into your .ctor() like that
WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.Transport);
I have never used this before as I always declare my bindings into web.config file but according to MSDN, this is what you should do.

Resources