Outlook AddIn Mobile Issue - not working in mobile whereas same code works for Desktop and web client - outlook-addin

I have the bellow error in Microsoft exchange server service, but only on mobiles as same code works for Desktops and web.
ERROR MESSAGE:
System.Net.WebException: The remote server returned an error: (401)
Unauthorized.
at System.Net.HttpWebRequest.GetResponse() at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
in
\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\EwsHttpWebRequest.cs:line
113 at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) in
\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:
line 821The request failed.
The remote server returned an error: (401) Unauthorized.
CODE SNIPPET:
// Create an ExchangeService object, set the credentials and the EWS URL.
ExchangeService exchangeService = new ExchangeService();
exchangeService.Credentials = new OAuthCredentials(attachmentToken);
exchangeService.Url = new Uri(ewsUrl);
exchangeService.UseDefaultCredentials = true;
exchangeService.PreAuthenticate = true;
try
{
var getAttachmentsResponse =exchangeService.GetAttachments(attachmentIds.ToArray(),null,new PropertySet(BasePropertySet.FirstClassProperties,ItemSchema.MimeContent));
}
catch (Exception ex)
{
var errMsg = ex.Message;
var errInnerException = ex.InnerException;
message += "Inner Exception :" + errInnerException;
}

Related

HTTP Error 401 with NLog WebService target with windows auth

Using NLog webservice target
https://github.com/nlog/NLog/wiki/WebService-target
I am getting a 401 when the target api is using windows auth.
Error Error when sending to Webservice: ws Exception: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
If I allow anonymous, it all works
Im trying to use impersonation in the call to the logging step. However, the above exception is generated in the NLog internal log file (i turned that on).
if (user.ImpersonateValidUser())
{
try
{
Logger logger = LogManager.GetCurrentClassLogger();
LogEntry l = new LogEntry()
{
AppName = "MyTestController",
LoggedOnDate = DateTime.Now,
LogMessage = "this is a test",
LogType = 1,
ServerName = "dev-test3"
};
logger.Error(l);
}
}
How can I call a webservice target that uses windows auth?
Unfortunately the Webservice target isn't supporting authentication. You could use the LogReceiverService target, see also How can I enable Security in LogReceiverService (NLog)

CRM OrganizationServiceProxy authentication issue

We have an issue where our web app calls to CRM via Microsoft.Xrm.Sdk OriganizationServiceProxy are failing to authenticate. The issue appears to be environment specific i.e. the calls work on our DEV web server but fail when the app is promoted to our System Test environment. The code that fails is as follows:
using (var serviceProxy = this.serviceFactory.Impersonate(userProvider.PrincipalUserName).ServiceProxy)
{
var countResult = serviceProxy.RetrieveMultiple(new FetchExpression(query));
int? count = 0;
var entity = countResult.Entities.FirstOrDefault();
if (entity != null)
{
count = (int?)((AliasedValue)entity["activity_count"]).Value;
}
return count.Value;
}
The error that appears in our logs is:
System.ServiceModel.Security.SecurityNegotiationException: The caller was not authenticated by the service. ---> System.ServiceModel.FaultException: The request for security token could not be satisfied because authentication failed.
at System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target)
at System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState)
--- End of inner exception stack trace ---
I have double checked the apppool identity of the IIS site and CRM settings. Is there anything obvious here that we may have missed?
I found the connection to CRM Online was taking the longest time so I create one instance to pass round of the OrganizationServiceProxy with explicit credentials that I can easily switch between environments.
IServiceManagement<IOrganizationService> management = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(CrmUrl));
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = CrmUserName;
credentials.UserName.Password = CrmPassword;
AuthenticationCredentials authCredentials = management.Authenticate(new AuthenticationCredentials { ClientCredentials = credentials });
SecurityTokenResponse securityTokenResponse = authCredentials.SecurityTokenResponse;
OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(management, securityTokenResponse);
orgProxy.EnableProxyTypes();
_xrmService = new XrmServiceContext(orgProxy)

WCF net.tcp binding service consume

I have following WCF Client code to consume WCF Service :
static void Main(string[] args)
{
IService1 vService;
NetTcpBinding b = new NetTcpBinding();
b.Security.Mode = SecurityMode.Message;
b.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
EndpointAddress vEndPoint = new EndpointAddress("net.tcp://115.127.1.226/myservice/");
ChannelFactory<IService1> cf = new ChannelFactory<IService1>(b, vEndPoint);
vService = cf.CreateChannel();
try
{
Console.WriteLine("Result from the system " + vService.HellowWorld());
}
catch (Exception ex)
{
Console.WriteLine("Error Occured while connection establish to " + vEndPoint.Uri.ToString());
}
Console.ReadKey();
}
When i run it locally it run successfully.
But When i try to consume my WCF Service remotely it Occurred a exception any one suggest
me how can i solve this problem?
My Exception message is :
Could not connect to net.tcp://115.127.1.226/myservice/. The connection attempt lasted for a time span of 00:00:21.0282028. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
115.127.1.226:808.
try to use
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

C2DM server side ClientLogin with java problem

I'm trying to implement the server side of C2DM. I have registered my application with Google via the signup process and received an email confirmation, so my user/pwd should be good. The first step is to retrieve the auth token via the ClientLogin. When I run the code, I get a response code 403 / Forbidden. Anyone have any ideas?
log.info("Obtaining the Google C2DM Client Login token.");
// Make POST request
HttpResponse res = null;
try {
DefaultHttpClient client = new DefaultHttpClient();
URI uri = new URI("https://www.google.com/accounts/ClientLogin");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
params.add(new BasicNameValuePair("Email", "MY_ACCOUNT#gmail.com"));
params.add(new BasicNameValuePair("Password", "MY_PWD"));
params.add(new BasicNameValuePair("service", "ac2dm"));
params.add(new BasicNameValuePair("source", "MY_APP-V0.1"));
HttpPost post = new HttpPost(uri);
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
res = client.execute(post);
} catch (Exception e) {
log.error("Error obtaining the Google C2DM Client Login token.", e);
}
log.debug("response="+res);
if (res != null) {
log.debug("Response status code = "+res.getStatusLine().getStatusCode());
log.debug("Response status = "+res.getStatusLine().getReasonPhrase());
}
My problem was pointed out to me here:
http://blog.boxedice.com/2010/10/07/android-push-notifications-tutorial/
The "Password" parameter name should actually be "Passwd".
Thanks to Dannon for the answer.

WCF sending the same exception even if the service endpoint address is valid

I'm running into a really strange problem with WCF. I need to implement some recovery behavior for WCF service if not reachable endpoint IP address received or service can not bind.
The flow is simple if the application fail on exception on service creation it terminate it and request from user another IP address and perform another attempt to create the service. (The code snippet below). If the address is not valid I get "A TCP error (10049: The requested address is not valid in its context) occurred while listening on IP Endpoint=.121.10.11.11" exception, but for any reason if I try the second attempt with valid address I've got the same exception with wrong IP address from previous attempt. Here is a code:
ServiceHost service = null;
try
{
Uri[] uris = { new Uri(Constants.PROTOCOL + "://" + address + ":" + port) };
service = new ServiceHost(typeof(IRemoteService), uris);
NetTcpBinding tcpBinding =
WcfTcpRemoteServicesManager.LessLimitedNewNetTcpBinding(int.MaxValue,
int.MaxValue, int.MaxValue);
ServiceEndpoint ep = service.AddServiceEndpoint(implementedContract.FullName,
tcpBinding, serviceName);
var throttle =
service.Description.Behaviors.Find<ServiceThrottlingBehavior>();
if (throttle == null)
{
throttle = new ServiceThrottlingBehavior
{
MaxConcurrentCalls = Constants.MAX_CONCURRENT_CALLS,
MaxConcurrentSessions = Constants.MAX_CONCURRENT_SESSIONS,
MaxConcurrentInstances = Constants.MAX_CONCURRENT_INSTANCES
};
service.Description.Behaviors.Add(throttle);
}
service.Open();
}
catch (Exception e)
{
_debugLog.WriteLineMessage(
"Failed to open or create service exception. Exception message:" +
e.Message);
if (service!=null)
{
try
{
service.Close();
}
catch (Exception)
{
service.Abort();
service.Close();
throw e;
}
}
}
Thanks
You catch exception e, then later you catch a different exception, but you throw the original exception e.
Not sure if this is your problem, but it could result in you getting a confusing exception back.
EDIT
Now I have read it a bit more carefully.
The problem is a mismatch between the context and the address. I see that the code uses netTcpBinding:
Check that the address matches, what is the value of CONSTANTS.Protocol?
Check that there is no conflict in the configuration files.