CRM 2011 Dicovery Service FaultException - crm

I have asked the same question at http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/d5d00302-8f7b-4efc-873b-c54b3e29749d but didn't get an answer. So, I will give another try at stackoverflow.
I was running the example code from the crm 2011 training kit.
var creds = new ClientCredentials();
var dsp = new DiscoveryServiceProxy( dinfo, creds);
dsp.Authenticate();
var orgRequest = new RetrieveOrganizationRequest();
var response = dsp.Execute(orgRequest);
var orgResponse = response as RetrieveOrganizationsResponse;
if (orgResponse != null)
comboOrgs.ItemsSource = orgResponse.Details;
At the line of var response = dsp.Execute(orgRequest), I got the FaltException`1, the detailed message is as follows
System.ServiceModel.FaultException`1 was unhandled
Message=organizationName
Source=mscorlib
Action=http://schemas.microsoft.com/xrm/2011/Contracts/Discovery/IDiscoveryService/ExecuteDiscoveryServiceFaultFault
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Xrm.Sdk.Discovery.IDiscoveryService.Execute(DiscoveryRequest request)
at Microsoft.Xrm.Sdk.Client.DiscoveryServiceProxy.Execute(DiscoveryRequest request)
I was able to access the Discovery.svc file using browser. So the server url should be correct. Is this an authentication problem?

Is this for Microsoft CRM Online or on-premise? For Online, I know you would want to use something along the lines of what is found in the SDK -
// Connect to the Discovery service.
// The using statement assures that the service proxy will be properly disposed.
using (DiscoveryServiceProxy _serviceProxy = new DiscoveryServiceProxy(serverConfig.DiscoveryUri,
serverConfig.HomeRealmUri,
serverConfig.Credentials,
serverConfig.DeviceCredentials))
{
// You can choose to use the interface instead of the proxy.
IDiscoveryService service = _serviceProxy;
#region RetrieveOrganizations Message
// Retrieve details about all organizations discoverable via the
// Discovery service.
RetrieveOrganizationsRequest orgsRequest =
new RetrieveOrganizationsRequest()
{
AccessType = EndpointAccessType.Default,
Release = OrganizationRelease.Current
};
RetrieveOrganizationsResponse organizations =
(RetrieveOrganizationsResponse)service.Execute(orgsRequest);
}
There are overloads for the DiscoveryServiceProxy class but if you provide some more details on what you are trying to connect to, I think it will narrow it down.

Related

Java.Net.SocketException Error: Socket closed in System.net.Http httpClient, occurs only when sending files larger than 50kbs

I am making a program in xamarin, which uses http requests to get data from an API made in net.core 2.0, but some requests (most of them actually) culminate in the following error:
System.AggregateException: One or more errors occurred. ---> Java.Net.SocketException: Socket closed
at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <286213b9e14c442ba8d8d94cc9dbec8e>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <286213b9e14c442ba8d8d94cc9dbec8e>:0
at Java.Net.HttpURLConnection.get_ResponseCode () [0x0000a] in <b781ed64f1d743e7881ac038e0fbdf85>:0
at Xamarin.Android.Net.AndroidClientHandler+<>c__DisplayClass45_0.<DoProcessRequest>b__1 () [0x00000] in <b781ed64f1d743e7881ac038e0fbdf85>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
--- End of stack trace from previous location where exception was thrown ---
at Xamarin.Android.Net.AndroidClientHandler+<DoProcessRequest>d__45.MoveNext () [0x0036c] in <b781ed64f1d743e7881ac038e0fbdf85>:0
--- End of stack trace from previous location where exception was thrown ---
at Xamarin.Android.Net.AndroidClientHandler+<SendAsync>d__40.MoveNext () [0x00230] in <b781ed64f1d743e7881ac038e0fbdf85>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x0000f] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
at FonoApp.Services.DataService.SendImageAsync (System.String token, FonoApp.Model.Imagem imagem) [0x00059] in C:\Projetos Sorri\FonoApp\AppTeste\AppTeste\Services\DataService.cs:154
--- End of inner exception stack trace ---}
This error occurs in this code snippet:
public async Task<String> SendImage(string token, Imagem imagem)
{
string baseAddress = #"http://192.168.0.4:5000/" + VersaoApi + #"/Imagem/";
var json = JsonConvert.SerializeObject(imagem);
var contentString = new StringContent(json, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token);
try
{
HttpResponseMessage tokenResponse = client.PostAsync(baseAddress, contentString).Result;//Erro ocorre nesta linha
var jsonContent = tokenResponse.Content.ReadAsStringAsync().Result;
return jsonContent;
}
catch (Exception e)
{
return e.InnerException.Message.ToString();
}
}
From what I researched, and discovered from this error, means that the connection is being closed either by the server or by the client, but I can't even know who closes the connection suddenly let alone prevent this / exception error, I don't know if it matters but I am testing the app on an android 4.2-API 17 tablet. Thanks in advance for any guidance on this as I am still learning how to program in C #.
one thing I forgot to say before was that Postman API requests work without problems
I noticed something interesting the error I get only occurs when trying to send images larger than 100 kb by http request, how can I increase the send and receive weight limit on my server?
Firstly, you need to use await instead of Result() to make this method async:
var jsonContent = await tokenResponse.Content.ReadAsStringAsync();
And yes, this exception occurs when internet connection is lost. You can do these things to make your app more usable:
Display a warning message in try-catch block
Check internet connection by using Xamarin.Essentials.Connectivity plugin
Set a timeout for your HttpClient object and catch the TimeoutException to display proper message

Getting error when try to consume soap service from nop commerce

I'm developing a plugin were i have done something like this code
[ChildActionOnly]
[HttpPost,ActionName("Configure")]
[FormValueRequired("test")]
public ActionResult TestSms(SmsRobiModel model)
{
bd.com.robi.bmpws.CMPWebService objCmpService = new bd.com.robi.bmpws.CMPWebService();
bd.com.robi.bmpws.ServiceClass sc = objCmpService.SendTextMessage("username", "password", "sendernumber", "receivernumber", "test msg");
}
but I get an error on this line and here is the error:
bd.com.robi.bmpws.ServiceClass sc = objCmpService.SendTextMessage("username", "password", "sendernumber", "receivernumber", "test msg");
Getting an error when try to consume soap service from nopCommerce.
I am trying to develop a SMS plugin in nopCommerce. I did everything for
a plugin but the sms send method is not functioning.
A SMS provider give me a soap service URL. I added it into my class library project, build it and install it in nopCommerce.
I am getting this error:
System.Net.WebException: The request failed with an empty response. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at Nop.Plugin.SMS.Robi.bd.com.robi.bmpws.CMPWebService.SendTextMessage(String Username, String Password, String From, String To, String Message) at Nop.Plugin.SMS.Robi.SmsRobiProvider.SendSms(String text, Int32 orderId, SmsRobiSettings settings) at Nop.Plugin.SMS.Robi.OrderPlacedEventConsumer.HandleEvent(OrderPlacedEvent eventMessage) at Nop.Services.Events.EventPublisher.PublishToConsumer[T](IConsumer`1 x, T eventMessage) in d:\MahadyLiveProjects\eshoptest\Libraries\Nop.Services\Events\EventPublisher.cs:line 40

Sequence contains no elements error when reading metadata

I am using Kentor Auth Services and trying to get it to work with Thinktecture Identity Server. I am getting this error when reading the metadata:
Sequence contains no elements
Here is the code that I am using in the Startup.cs file:
var authServicesOptions = new Kentor.AuthServices.Owin.KentorAuthServicesAuthenticationOptions(false)
{
SPOptions = new SPOptions
{
EntityId = new EntityId("https://dev.identity.research.ufl.edu:4432/AuthServices")
},
SignInAsAuthenticationType = signInAsType,
AuthenticationType = "saml2p",
Caption = "SAML2p",
};
authServicesOptions.IdentityProviders.Add(new IdentityProvider(
new EntityId("urn:edu:ufl:dev:00856"),
authServicesOptions.SPOptions)
{
MetadataLocation = "https://dev.identity.research.ufl.edu:4432/EMvc/Metadata.txt",
});
app.UseKentorAuthServicesAuthentication(authServicesOptions);
Also I'm including the error message and part of the stack trace below.
Thanks very much for any help you can provide in how I should troubleshoot this error.
Sincerely,
Cheryl Bearden
[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.Single(IEnumerable1 source) +310
Kentor.AuthServices.IdentityProvider.ReadMetadataIdpDescriptor(ExtendedEntityDescriptor metadata) +108
Kentor.AuthServices.IdentityProvider.ReadMetadata(ExtendedEntityDescriptor metadata) +132
Kentor.AuthServices.IdentityProvider.DoLoadMetadata() +127
Kentor.AuthServices.IdentityProvider.ReloadMetadataIfRequired() +169
Kentor.AuthServices.IdentityProvider.CreateAuthenticateRequest(AuthServicesUrls authServicesUrls) +73
Kentor.AuthServices.WebSso.SignInCommand.InitiateLoginToIdp(IOptions options, IDictionary2 relayData, AuthServicesUrls urls, IdentityProvider idp, Uri returnUrl) +36
Kentor.AuthServices.WebSso.SignInCommand.Run(EntityId idpEntityId, String returnPath, HttpRequestData request, IOptions options, IDictionary`2 relayData) +447
Kentor.AuthServices.Owin.d__1.MoveNext() +781

.Net SoapClient Connection Was Not Closed

I am trying to access a 3rd party asmx service (from my ASP.Net MVC 4 app). Mostly it works fine, then suddenly I start seeing an error:
The connection was not closed. The connection's current state is open.
This issue goes away for some time and everything works fine. Then it appears again.
I suspected proxy or network settings but changing those did not help. I am able to 'update service reference' without issues which means I can access the service properly.
Is it possible that this error is generated at the service end and is bubbling to my app?
Can I determine if the issue is at the client end or mine?
Thanks
Details:
[System.ServiceModel.FaultException]: {"Server was unable to process request. ---> The connection was not closed. The connection's current state is open."}
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyTDI.ClientWebServices.TDIWS_SalesManagement.WS_SalesManagementModuleSoap.GetAgentCommissions(String Agency_RegNo, DateTime StartDate, DateTime EndDate, Int32 PageNo)
at MyTDI.ClientWebServices.TDIWS_SalesManagement.WS_SalesManagementModuleSoapClient.GetAgentCommissions(String Agency_RegNo, DateTime StartDate, DateTime EndDate, Int32 PageNo) in d:\Projects\TPLTDI\MyTDIPortal\MyTDI.ClientWebServices\Service References\TDIWS_SalesManagement\Reference.cs:line 111
at MyTDI.ClientWebServices.Sales.SalesManagementWebService.ListAgentCommissions(String agentId, DateTime startDate, DateTime endDate, Int32 pageNo) in d:\Projects\TPLTDI\MyTDIPortal\MyTDI.ClientWebServices\Sales\SalesManagementWebService.cs:line 31
Code
DataSet ds = null;
using( WS_SalesManagementModuleSoapClient client = new WS_SalesManagementModuleSoapClient( ) )
{
try
{
ds = client.GetAgentCommissions( agentId , startDate , endDate , pageNo );
}
catch( Exception ex )
{
logger.Error( ex , "" );
throw new Exception( "Unable to obtain commissions data from server." );
}
}
The error occurs in the database connection. Make sure that the SqlConnection object is properly disposed in your server code (a good practice is to wrap your code with using statements).

UserPrincipal.FindByIdentity sometimes failing with DirectoryServicesCOMException: An operations error occurred

We are a team where everyone of us experience this somewhat random error. The error is listed below and appears on the line: UserPrincipal.FindByIdentity(principalContext, windowsPrincipal.Identity.Name);
It works just fine several days/weeks/months, and then one of us get this error.
On our test server, where we do not deploy changes to as frequently as our local machines, it works for many months before we get this error.
If we change the application pool from ApplicationPoolIdentity to NetworkService, that works. However, after switching back to ApplicationPoolIdentity the same error appears.
IISreset does not help.
Rebooting the computer always solves the problem, so the ApplicationPoolIdentity has no problems to authenticate us on a daily basis.
This is the code (somewhat modified) that we use:
var windowsPrincipal = principal as WindowsPrincipal;
if (windowsPrincipal == null)
return null;
try
{
var principalContext = new PrincipalContext(ContextType.Domain);
var userPrincipal = UserPrincipal.FindByIdentity(principalContext, windowsPrincipal.Identity.Name);
if (userPrincipal == null) return null;
return userPrincipal.Surname;
}
Here is the error message:
An operations error occurred.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.
Source Error:
var principalContext = new PrincipalContext(ContextType.Domain);
var userPrincipal = UserPrincipal.FindByIdentity(principalContext, windowsPrincipal.Identity.Name);
Stack Trace:
[DirectoryServicesCOMException (0x80072020): An operations error occurred.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +628309
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
System.DirectoryServices.PropertyValueCollection.PopulateList() +29
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +63
System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +163
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() +521413
System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() +51
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +161
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +42
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +29
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue) +81
If you are not disposing it in a finaly block, you'll eventually run out of resources...
Using (var principalContext = new PrincipalContext(ContextType.Domain))
{
var userPrincipal = UserPrincipal.FindByIdentity(principalContext,
windowsPrincipal.Identity.Name);
if (userPrincipal == null) return null;
return userPrincipal.Surname;
}
should help

Resources