We want to integrate our site with MSDynamics CRM.To get data from our site to MSDynamics CRM,we want to call webservice of our site from MSDynamics CRM.How could we do this?We would be grateful if provided some example codes.
Try this May be helpful:
http://technet.microsoft.com/en-us/library/aa613627.aspx
http://msdn.microsoft.com/en-us/library/cc150838.aspx
use the link above may be helpful
I think create a web service that your site refer and using the Dynamics CRM sdk to do operation to CRM.
Example:
WCF
[ServiceContract]
public interface IService1
{
[OperationContract]
Guid CreateContact(String firstname, String lastname, String email);
}
Implementation using CRM SDK
public class Service1 : IService1
{
readonly IOrganizationService _service = new OrganizationService("CRMConnectionStringName");
public Guid CreateContact(string firstname, string lastname, string email)
{
var contact = new Entity("contact");
contact.Attributes["firstname"] = firstname;
contact.Attributes["lastname"] = lastname;
contact.Attributes["emailaddress1"] = email;
var contactId = _service.Create(contact);
return contactId;
}
}
Related
So I set up an ASP.NET MVC app with Identity and Oauth2 using this tutorial:
http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/
I can't recommend that tutorial enough if you are trying to do this, it is quite excellent. I'm now able to login using the usernames / passwords stored in the MVC database with the following HTTP request:
POST /token HTTP/1.1
Host: mymvcsite.azurewebsites.net
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
grant_type=password&username=MyUserName&password=MyPassword
I used javascript just as a proof of concept using an HttpRequest and it works amazingly well. I get a token back and everything. My response looks like this:
{
"access_token": "A Really long character string",
"token_type": "bearer",
"expires_in": 86399
}
So everything works outside of Xamarin at the moment and now I'm trying to wrap my head around how to plug all this into my Xamarin project. My first source of confusion is the Xamarin.auth plugin and how it might be used in this case, if at all. I cannot find anything on this plugin that doesn't use Facebook or Google as the auth provider and what I'm doing doesn't seem to fit into that model where you have a client secret and and ClientID and the like. The second thing I'm trying to undertstand is what I'm doing with the token once I have it. The ultimate goal here is to create a few web services in the MVC site, have users authenticate against the MVC identity using oauth, then access those web services securely. So my questions are:
1) Would I use Xamain.auth in this case? If so, are there any good resources that have examples of what I'm trying to do?
2) Once I have the token, how do I secure a web service to expect an oauth2 token like this?
Great resource you've posted there. I've used that as well and I've built a whole (Xamarin) portable class library that automatically submits this token with every request etc.
In ASP.NET MVC it's as easy as adding the
[Authorize]
-attribute over your API-controllers. THis will instantly secure them if you followed the guide properly.
After securing your API's you'll need to send requests containing the bearer token. This is how I implemented it in my projects:
// First logging in and getting a token:
public async Task<bool> OAuthLoginAsync(string username, string password)
{
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("username", username),
new KeyValuePair<string, string>("password", password),
new KeyValuePair<string, string>("grant_type", "password")
});
Token = await PostAndReadAsync<TokenResponse>(_oauthEndpointUri, formContent);
}
// this method is responsible for sending the request and returning an object
public async Task<T> PostAndReadAsync<T>(string path, HttpContent content)
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
var responseMessage = await httpClient.PostAsync(path, content, cancellationToken);
if (!responseMessage.IsSuccessStatusCode) {
throw new Exception("Something went wrong...");
}
return await responseMessage.Content.ReadAsAsync<T>(cancellationToken);
}
}
Token definition:
public class TokenResponse
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }
[JsonProperty("token_type")]
public string TokenType { get; set; }
[JsonProperty("expires_in")]
public int ExpiresIn { get; set; }
[JsonProperty("refresh_token")]
public string RefreshToken { get; set; }
[JsonProperty("as:client_id")]
public string ClientId { get; set; }
[JsonProperty("userName")]
public string UserName { get; set; }
[JsonProperty(".issued")]
public DateTime IssueDate { get; set; }
[JsonProperty(".expires")]
public DateTime ExpireDate { get; set; }
}
Then in any subsequent api calls (where you should be providing an oauth token) you should add the access token.
HttpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Token.AccessToken);
As an added bonus the PostAndReadAsync method specified earlier can be reused to call any other resource (as it returns <T>) so it's reusable.
I hope this will help you (and many other facing the same issue). Feel free to ask for more information if this isn't complete for your situation.
Please note that I removed all try/catches and cancellationtokens for simplicity.
You'll need the following nuget packages in your (shared) mobile project:
Microsoft.Bcl
Microsoft.Bcl.Build
Microsoft.Bcl.Http
Microsoft.AspNet.WebApi.Client
Newtonsoft.Json
I am developing a Restful web service which allow user to set all parameters in POJO and send it to server side web service, then web service will store this data and return generated Id back to client. But my POJO has parent-child relationship that contain set of POJO, So how can I do this using RESTful web service. I also written a code to fetch data from server using web service and its working fine. But for this issue please help me.
Thanks.
I am not sure if I understood your question correctly. I guess some sample code will help. If you are using RestTemplate then serializing and deserializing will be done for you automatically. RestTemplate uses Jackson to parse JSON so you don't need to worry about parent/child relationship in your POJO.
So here is an example. There are 1000's of examples out there on internet. Thats how I learnt.
RestTemplate restclient = new RestTemplate();
Product product = restclient.getForObject(url,Product.class);
System.out.println(product.getCoupons().getName());
Where as product is (I completely made this up myself),
public class Product {
#JsonProperty("id")
private String id;
#JsonProperty("coupons")
private Coupons coupons;
#JsonProperty("id")
public String getId() {
return id;
}
#JsonProperty("id")
public void setId(String id) {
this.id = id;
}
#JsonProperty("coupons")
public Coupons getCoupons() {
return coupons;
}
#JsonProperty("coupons")
public void setCoupons(Coupons coupons) {
this.coupons = coupons;
}
}
public class Coupons {
#JsonProperty("name")
private String name;
#JsonProperty("name")
public String getName() {
return name;
}
#JsonProperty("name")
public void setName(String name) {
this.name = name;
}
}
Let me know if I misunderstood your question, I can update my answer accordingly.
We have MVVM Silverlight application. I am trying to open web url from button click event which happen on client side viewmodel and through invoke method needs to open web url in new browser.
I am using Process.Start method as describe below in Server side code.
var URL = #"http://SiteSelect.aspx";
SecureString secure = new SecureString();
char[] passwordChars = Properties.Settings.Default.Password.ToCharArray();
//converting string to securestring...found from internet
foreach (char c in passwordChars)
{
secure.AppendChar(c);
}
Process.Start(URL,"",Properties.Settings.Default.User,secure,"agent");
this throws an error related to user name and password. I checked user name and password is correct. Anyone have solution or any other method I can able to use?
Thanks,
You create a helper class:
public static class CommonHelper
{
private class HyperlinkButtonWrapper : HyperlinkButton
{
public void OpenURL(string navigateUri)
{
OpenURL(new Uri(navigateUri, UriKind.Absolute));
}
public void OpenURL(Uri navigateUri)
{
base.NavigateUri = navigateUri;
base.TargetName = "_blank";
base.OnClick();
}
}
public static void OpenURL(string navigateUri)
{
new HyperlinkButtonWrapper().OpenURL(navigateUri);
}
}
Usage:
CommonHelper.OpenURL(#"http://SiteSelect.aspx");
You could use this as well :
using System.Windows.Browser;
var uri = new Uri("http://foo.fr");
HtmlPage.Window.Navigate(uri, "_blank");
Easiest way to pass credentials is to put them in the URL, however it's not very secured. Ie:
http://user:password#foo.fr
I have an InfoPath 2010 form that queries a web service. The web service is expecting the entire InfoPath form as an XML string parameter. By an XML string I mean the string on the format
<my:myFields xmlns:my=...>
<my:Name>UserName</my:Name>
...
</my:myFields>
The web service will then process the string and return a result to the InfoPath form.
I have tried to pass the root element, ".", but at the web service end I am receiving the values only formatted by \r\n and \t. Any idea on how to pass the XML tags and the values.
I have found a workaround by passing the list name and the form name to a web service. The web service, which is hosted in SharePoint, will then get the XML of the form.
Here is the code for reference:
public class InfoPathHelper
{
private string _listName;
private string _fileUrl;
public InfoPathHelper(string listName, string fileName)
{
_listName = listName;
_fileUrl = string.Format("{0}/{1}.xml", listName, fileName);
}
public string GetFormXml()
{
using (SPWeb web = SPContext.Current.Web)
{
SPList lib = web.Lists[_listName];
SPFile file = lib.RootFolder.Files[_fileUrl];
XmlDocument doc = new XmlDocument();
doc.Load(file.OpenBinaryStream());
return doc.OuterXml;
}
}
}
I'm using .NET 2.0. There are any alternative to .NET WSE 3.0?
Is it possible to pass username and password in soap header without any toolkit, only using code?
Thanks
(This suggestion might be way off, since I'm not sure if you mean some special WS.* headers, or just any custom header... and I've never heard of WSE)
I call a webservice with user/pass in a header as follows. It's not production code, but the snippets should illustrate it.
On the client:
string userName = "someusername";
string password = "somepass";
//create the custom header object
MyService.AuthHeader authHeader = new MyService.AuthHeader();
authHeader.UserName = userName;
authHeader.Password = password;
//create the WS-proxy
MyService.SomeWebservice someWS = new MyService.SomeWebservice();
//set headers
someWS.AuthHeaderValue = authHeader;
someWS.SomeMethod();
The webservice:
public class SomeWebservice : System.Web.Services.WebService
{
public AuthHeader Authentication = null; //For receiving the authentication header from the SOAP client (you will never assign this property in user code, .NET handles the plumbing based on the [SoapHeader("Authentication")] attribute
[WebMethod(Description = "Some webservice method")]
[SoapHeader("Authentication")]
public void SomeMethod()
{
string suppliedUserName = Authentication.UserName;
string suppliedPassword = Authentication.Password;
}
}
The AuthHeader class: (defined at the "WS end")
public class AuthHeader : SoapHeader
{
public string UserName = null;
public string Password = null;
}
It's possible to alter the SOAP Message using SOAP Extensions including the required SOAP Header