Hi,
I try to call a web service in plugin,th web service create a contact, so i need to call this service in plugin where the message is crate and the primary entity is account,
please some one publish an example some..
thank you
*This post is locked for comments
Is it working now?
If not, you might actually want to try it in a console app first. There are some limitations when you deploy plugins in sandbox:
msdn.microsoft.com/.../gg334752.aspx
For example, "localhost" is not allowed..(have to use a dns name instead)
Although, if you are onprem, you don't have to use sandbox
this is my code
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Context = Info passed to the plugin at runtime
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
//Service = access to data for modification
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
// Adding Basic Http Binding and its properties.
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = "BasicHttpBinding_Service";
myBinding.Security.Mode = BasicHttpSecurityMode.None;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
{
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "account")
{
try
{
// Endpoint Address defining the asmx Service to be called.
EndpointAddress endPointAddress = new EndpointAddress(@"localhost/WebService1.asmx;);
// Call to the Web Service using the Binding and End Point Address.
localhost.WebService1 srv = new localhost.WebService1();
srv.CreateContact();
}
catch (Exception ex) { }
}
}
}
}
Hi, you can see this example: code.msdn.microsoft.com/.../How-to-call-Rest-Service-b0b188df
thanks
A.G.
The only thing you need to know about this one is that you need to configure your SOAP webservice inside your plugin code. Configuration that is generated by adding web service reference will not work in CRM plugin.
call external webservice
Hi Ghazi,
Do you want call external webservice or want to use IOrganizationService ?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156