How to connect react native app with ASP.NET Web services using SQL Server?











up vote
0
down vote

favorite












I am trying to connect my ASP.NET web services with React-Native app. I am using SQL Server with ASP.NET web services now want to connect react-native app with my ASP.NET - any solution for this?



Now I am stuck and searched a lot but I have not yet found any solution.










share|improve this question
























  • Your React Native app doesn't need to know anything about MSSQL. Your React app should talk to your web services via HTTP. MSSQL is really irrelevant here, as the data storage used by your web service shouldn't make any difference.
    – mason
    Nov 19 at 18:35










  • I created webservices in asp.net and webservices is fetching data from MSSQL Server and want to integrate my react-native app with webservice.
    – Ali Ghaffari
    Nov 19 at 18:54










  • Yes, I understood that. My point is that your React app doesn't need to care about what data storage mechanism the web service is using. It's called Separation of Concerns.
    – mason
    Nov 19 at 20:10















up vote
0
down vote

favorite












I am trying to connect my ASP.NET web services with React-Native app. I am using SQL Server with ASP.NET web services now want to connect react-native app with my ASP.NET - any solution for this?



Now I am stuck and searched a lot but I have not yet found any solution.










share|improve this question
























  • Your React Native app doesn't need to know anything about MSSQL. Your React app should talk to your web services via HTTP. MSSQL is really irrelevant here, as the data storage used by your web service shouldn't make any difference.
    – mason
    Nov 19 at 18:35










  • I created webservices in asp.net and webservices is fetching data from MSSQL Server and want to integrate my react-native app with webservice.
    – Ali Ghaffari
    Nov 19 at 18:54










  • Yes, I understood that. My point is that your React app doesn't need to care about what data storage mechanism the web service is using. It's called Separation of Concerns.
    – mason
    Nov 19 at 20:10













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to connect my ASP.NET web services with React-Native app. I am using SQL Server with ASP.NET web services now want to connect react-native app with my ASP.NET - any solution for this?



Now I am stuck and searched a lot but I have not yet found any solution.










share|improve this question















I am trying to connect my ASP.NET web services with React-Native app. I am using SQL Server with ASP.NET web services now want to connect react-native app with my ASP.NET - any solution for this?



Now I am stuck and searched a lot but I have not yet found any solution.







asp.net sql-server reactjs react-native






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 19:40









marc_s

568k12810991249




568k12810991249










asked Nov 19 at 18:19









Ali Ghaffari

86




86












  • Your React Native app doesn't need to know anything about MSSQL. Your React app should talk to your web services via HTTP. MSSQL is really irrelevant here, as the data storage used by your web service shouldn't make any difference.
    – mason
    Nov 19 at 18:35










  • I created webservices in asp.net and webservices is fetching data from MSSQL Server and want to integrate my react-native app with webservice.
    – Ali Ghaffari
    Nov 19 at 18:54










  • Yes, I understood that. My point is that your React app doesn't need to care about what data storage mechanism the web service is using. It's called Separation of Concerns.
    – mason
    Nov 19 at 20:10


















  • Your React Native app doesn't need to know anything about MSSQL. Your React app should talk to your web services via HTTP. MSSQL is really irrelevant here, as the data storage used by your web service shouldn't make any difference.
    – mason
    Nov 19 at 18:35










  • I created webservices in asp.net and webservices is fetching data from MSSQL Server and want to integrate my react-native app with webservice.
    – Ali Ghaffari
    Nov 19 at 18:54










  • Yes, I understood that. My point is that your React app doesn't need to care about what data storage mechanism the web service is using. It's called Separation of Concerns.
    – mason
    Nov 19 at 20:10
















Your React Native app doesn't need to know anything about MSSQL. Your React app should talk to your web services via HTTP. MSSQL is really irrelevant here, as the data storage used by your web service shouldn't make any difference.
– mason
Nov 19 at 18:35




Your React Native app doesn't need to know anything about MSSQL. Your React app should talk to your web services via HTTP. MSSQL is really irrelevant here, as the data storage used by your web service shouldn't make any difference.
– mason
Nov 19 at 18:35












I created webservices in asp.net and webservices is fetching data from MSSQL Server and want to integrate my react-native app with webservice.
– Ali Ghaffari
Nov 19 at 18:54




I created webservices in asp.net and webservices is fetching data from MSSQL Server and want to integrate my react-native app with webservice.
– Ali Ghaffari
Nov 19 at 18:54












Yes, I understood that. My point is that your React app doesn't need to care about what data storage mechanism the web service is using. It's called Separation of Concerns.
– mason
Nov 19 at 20:10




Yes, I understood that. My point is that your React app doesn't need to care about what data storage mechanism the web service is using. It's called Separation of Concerns.
– mason
Nov 19 at 20:10












3 Answers
3






active

oldest

votes

















up vote
1
down vote













Your web service needs to return data in JSON format. You know which urls are defined for which actions.



Let's say you have an endpoint like: http://mywebservice.com/GetEmployees.



In your React app, you're going to run XMLHttpRequest or Fetch using those web service urls, such as http://mywebservice.com/GetEmployees. You will process the returned JSON in your React App and display it with something like the JavaScript map function.



As the others have mentioned, your web service is going to be talking to SQL Server. Your React Native app will not be dealing directly the SQL Server.






share|improve this answer





















  • Thanks for response. Can you send me any example of code link? ForExample: I have one webservice developed in asp.net using C# and getting data like Name of anyone from database. I wan't to show this Name on my React-Native app using this service. Can you help me please?
    – Ali Ghaffari
    Nov 19 at 20:27










  • Yes, I'll post something tonight.
    – Charles Owen
    Nov 19 at 20:40










  • okay I'll see the code of react-native to connect my app with webservices.
    – Ali Ghaffari
    Nov 19 at 21:12


















up vote
0
down vote













class EwdsUserBox extends React.Component {
constructor(props) {
super(props);
this.state = {
data:
};
}
loadCommentsFromServer(page=0, count=25) {
const xhr = new XMLHttpRequest();
let params = "?page="+page+"&count=" + count;
xhr.open('get', this.props.url, true);
xhr.onload = function() {
var data = JSON.parse(xhr.responseText);
this.setState({ data: data});
}.bind(this);
xhr.send();
}
componentDidMount() {
this.loadCommentsFromServer(0,25);
}
render() {
const ewds = this.state.data;
var count = 0;

return (
<div className="ewdsUserBox body-content">
<EwdsUserSummary total={ewds.length} disabled={count} locked={0}/>
<EwdsUserTable data={ewds} />
</div>
);

}
}


This is for ReactJS but you'll notice I'm using an XMLHttpRequest to retrieve the JSON data. EwdsUserBox is just my container component. I'll then pass this data to subcomponents, in this case a user table and user row.



const EwdsUserTable = (props) => {   
let counter = 0;
let ewdsData = props.data;
if (ewdsData) {
var ewdsUserRows = ewdsData.map(function (ewdsUser) {
return (
<EwdsUserRow ewdsUser={ewdsUser} key={counter++} />
);
});
}
return (
<div className="ewdsUserTable" >
<table id="mytable" className="table table-striped table-bordered table-condensed fixed">
<caption>EWDS Users</caption>
<thead>
<tr>
<th className="sort" type="string">User Name</th>
<th className="sort" type="string">Email Address</th>
<th>Pwd Changed</th>
<th type="date">Last Logon</th>
<th>Locked</th>
<th className="sort" type="string">Disabled</th>
<th></th>
</tr>
</thead>
<tbody>
{ewdsUserRows}
</tbody>
</table>
</div>
);


};



Here's where I'm actually displaying the data.



class EwdsUserRow extends React.Component {     

render() {
const {UserName, EmailAddress, AccountCreated, PasswordChanged, AccountName,
Locked, Enabled} = this.props.ewdsUser;

return (
<tr>
<td>{UserName}</td>
<td>{EmailAddress}</td>
<td>{AccountCreated}</td>
<td>{PasswordChanged}</td>
<td>{Locked}</td>
<td>{Enabled}</td>
</tr>
);
}
}





share|improve this answer





















  • Thanks for your answer but here i am facing one issue where I have to paste the url. Kindly make a simple helloworld reactnative app where it will be showing a username and posting username using webservices. Please
    – Ali Ghaffari
    Nov 25 at 9:39


















up vote
0
down vote













Here's the web service part. Let's say I'm just returning a corporate leader to the client. I can either create a Web API controller or an MVC controller that returns a JsonResult. leader here is merely a Leader c# object. I've chosen the latter. The key here is that we're returning JSON data back to the client in the form of a JSON object.



    [HttpGet]
public JsonResult Leader() {
return Json(leader, JsonRequestBehavior.AllowGet);
}


Let's assume the endpoint of this service will be: http://www.example.com/Leader. Now my React Native app is going to need to reference this url There are various apis for retrieving data from a web service, but I like using Fetch or you could use Axios, etc. My example below will be using Fetch. For the most basic React Native app, we'd just using the componentDidMount() event to run the Fetch request, and put leader in a state object. Note: This is an oversimplified answer and I haven't tested it out.



import React, {Component} from 'react';
import { Text, Card } from 'react-native';

export default class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
leader = {},
errMessage = ''
}
}

componentDidMount() {
fetch(url)
.then(response => {
if (response.ok) {
return response;
} else {
let error = new Error('Error ' + response.status + ': ' + response.statusText);
error.response = response;
throw error;
}
},
error => {
let errmess = new Error(error.message);
throw errmess;
})
.then(response => response.json())
.then(leaders => {
this.setState({ leader: leader });
})
.catch(error => {
this.setState({ errMessage: error.message });
});
}
render () {
const {lastName, firstName} = this.state.leader;
return (
<Card
title="Our beloved leader">
<Text>`${firstName} ${lastName}/></Text>
</Card>
);
}
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380510%2fhow-to-connect-react-native-app-with-asp-net-web-services-using-sql-server%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Your web service needs to return data in JSON format. You know which urls are defined for which actions.



    Let's say you have an endpoint like: http://mywebservice.com/GetEmployees.



    In your React app, you're going to run XMLHttpRequest or Fetch using those web service urls, such as http://mywebservice.com/GetEmployees. You will process the returned JSON in your React App and display it with something like the JavaScript map function.



    As the others have mentioned, your web service is going to be talking to SQL Server. Your React Native app will not be dealing directly the SQL Server.






    share|improve this answer





















    • Thanks for response. Can you send me any example of code link? ForExample: I have one webservice developed in asp.net using C# and getting data like Name of anyone from database. I wan't to show this Name on my React-Native app using this service. Can you help me please?
      – Ali Ghaffari
      Nov 19 at 20:27










    • Yes, I'll post something tonight.
      – Charles Owen
      Nov 19 at 20:40










    • okay I'll see the code of react-native to connect my app with webservices.
      – Ali Ghaffari
      Nov 19 at 21:12















    up vote
    1
    down vote













    Your web service needs to return data in JSON format. You know which urls are defined for which actions.



    Let's say you have an endpoint like: http://mywebservice.com/GetEmployees.



    In your React app, you're going to run XMLHttpRequest or Fetch using those web service urls, such as http://mywebservice.com/GetEmployees. You will process the returned JSON in your React App and display it with something like the JavaScript map function.



    As the others have mentioned, your web service is going to be talking to SQL Server. Your React Native app will not be dealing directly the SQL Server.






    share|improve this answer





















    • Thanks for response. Can you send me any example of code link? ForExample: I have one webservice developed in asp.net using C# and getting data like Name of anyone from database. I wan't to show this Name on my React-Native app using this service. Can you help me please?
      – Ali Ghaffari
      Nov 19 at 20:27










    • Yes, I'll post something tonight.
      – Charles Owen
      Nov 19 at 20:40










    • okay I'll see the code of react-native to connect my app with webservices.
      – Ali Ghaffari
      Nov 19 at 21:12













    up vote
    1
    down vote










    up vote
    1
    down vote









    Your web service needs to return data in JSON format. You know which urls are defined for which actions.



    Let's say you have an endpoint like: http://mywebservice.com/GetEmployees.



    In your React app, you're going to run XMLHttpRequest or Fetch using those web service urls, such as http://mywebservice.com/GetEmployees. You will process the returned JSON in your React App and display it with something like the JavaScript map function.



    As the others have mentioned, your web service is going to be talking to SQL Server. Your React Native app will not be dealing directly the SQL Server.






    share|improve this answer












    Your web service needs to return data in JSON format. You know which urls are defined for which actions.



    Let's say you have an endpoint like: http://mywebservice.com/GetEmployees.



    In your React app, you're going to run XMLHttpRequest or Fetch using those web service urls, such as http://mywebservice.com/GetEmployees. You will process the returned JSON in your React App and display it with something like the JavaScript map function.



    As the others have mentioned, your web service is going to be talking to SQL Server. Your React Native app will not be dealing directly the SQL Server.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 19 at 20:03









    Charles Owen

    51547




    51547












    • Thanks for response. Can you send me any example of code link? ForExample: I have one webservice developed in asp.net using C# and getting data like Name of anyone from database. I wan't to show this Name on my React-Native app using this service. Can you help me please?
      – Ali Ghaffari
      Nov 19 at 20:27










    • Yes, I'll post something tonight.
      – Charles Owen
      Nov 19 at 20:40










    • okay I'll see the code of react-native to connect my app with webservices.
      – Ali Ghaffari
      Nov 19 at 21:12


















    • Thanks for response. Can you send me any example of code link? ForExample: I have one webservice developed in asp.net using C# and getting data like Name of anyone from database. I wan't to show this Name on my React-Native app using this service. Can you help me please?
      – Ali Ghaffari
      Nov 19 at 20:27










    • Yes, I'll post something tonight.
      – Charles Owen
      Nov 19 at 20:40










    • okay I'll see the code of react-native to connect my app with webservices.
      – Ali Ghaffari
      Nov 19 at 21:12
















    Thanks for response. Can you send me any example of code link? ForExample: I have one webservice developed in asp.net using C# and getting data like Name of anyone from database. I wan't to show this Name on my React-Native app using this service. Can you help me please?
    – Ali Ghaffari
    Nov 19 at 20:27




    Thanks for response. Can you send me any example of code link? ForExample: I have one webservice developed in asp.net using C# and getting data like Name of anyone from database. I wan't to show this Name on my React-Native app using this service. Can you help me please?
    – Ali Ghaffari
    Nov 19 at 20:27












    Yes, I'll post something tonight.
    – Charles Owen
    Nov 19 at 20:40




    Yes, I'll post something tonight.
    – Charles Owen
    Nov 19 at 20:40












    okay I'll see the code of react-native to connect my app with webservices.
    – Ali Ghaffari
    Nov 19 at 21:12




    okay I'll see the code of react-native to connect my app with webservices.
    – Ali Ghaffari
    Nov 19 at 21:12












    up vote
    0
    down vote













    class EwdsUserBox extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
    data:
    };
    }
    loadCommentsFromServer(page=0, count=25) {
    const xhr = new XMLHttpRequest();
    let params = "?page="+page+"&count=" + count;
    xhr.open('get', this.props.url, true);
    xhr.onload = function() {
    var data = JSON.parse(xhr.responseText);
    this.setState({ data: data});
    }.bind(this);
    xhr.send();
    }
    componentDidMount() {
    this.loadCommentsFromServer(0,25);
    }
    render() {
    const ewds = this.state.data;
    var count = 0;

    return (
    <div className="ewdsUserBox body-content">
    <EwdsUserSummary total={ewds.length} disabled={count} locked={0}/>
    <EwdsUserTable data={ewds} />
    </div>
    );

    }
    }


    This is for ReactJS but you'll notice I'm using an XMLHttpRequest to retrieve the JSON data. EwdsUserBox is just my container component. I'll then pass this data to subcomponents, in this case a user table and user row.



    const EwdsUserTable = (props) => {   
    let counter = 0;
    let ewdsData = props.data;
    if (ewdsData) {
    var ewdsUserRows = ewdsData.map(function (ewdsUser) {
    return (
    <EwdsUserRow ewdsUser={ewdsUser} key={counter++} />
    );
    });
    }
    return (
    <div className="ewdsUserTable" >
    <table id="mytable" className="table table-striped table-bordered table-condensed fixed">
    <caption>EWDS Users</caption>
    <thead>
    <tr>
    <th className="sort" type="string">User Name</th>
    <th className="sort" type="string">Email Address</th>
    <th>Pwd Changed</th>
    <th type="date">Last Logon</th>
    <th>Locked</th>
    <th className="sort" type="string">Disabled</th>
    <th></th>
    </tr>
    </thead>
    <tbody>
    {ewdsUserRows}
    </tbody>
    </table>
    </div>
    );


    };



    Here's where I'm actually displaying the data.



    class EwdsUserRow extends React.Component {     

    render() {
    const {UserName, EmailAddress, AccountCreated, PasswordChanged, AccountName,
    Locked, Enabled} = this.props.ewdsUser;

    return (
    <tr>
    <td>{UserName}</td>
    <td>{EmailAddress}</td>
    <td>{AccountCreated}</td>
    <td>{PasswordChanged}</td>
    <td>{Locked}</td>
    <td>{Enabled}</td>
    </tr>
    );
    }
    }





    share|improve this answer





















    • Thanks for your answer but here i am facing one issue where I have to paste the url. Kindly make a simple helloworld reactnative app where it will be showing a username and posting username using webservices. Please
      – Ali Ghaffari
      Nov 25 at 9:39















    up vote
    0
    down vote













    class EwdsUserBox extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
    data:
    };
    }
    loadCommentsFromServer(page=0, count=25) {
    const xhr = new XMLHttpRequest();
    let params = "?page="+page+"&count=" + count;
    xhr.open('get', this.props.url, true);
    xhr.onload = function() {
    var data = JSON.parse(xhr.responseText);
    this.setState({ data: data});
    }.bind(this);
    xhr.send();
    }
    componentDidMount() {
    this.loadCommentsFromServer(0,25);
    }
    render() {
    const ewds = this.state.data;
    var count = 0;

    return (
    <div className="ewdsUserBox body-content">
    <EwdsUserSummary total={ewds.length} disabled={count} locked={0}/>
    <EwdsUserTable data={ewds} />
    </div>
    );

    }
    }


    This is for ReactJS but you'll notice I'm using an XMLHttpRequest to retrieve the JSON data. EwdsUserBox is just my container component. I'll then pass this data to subcomponents, in this case a user table and user row.



    const EwdsUserTable = (props) => {   
    let counter = 0;
    let ewdsData = props.data;
    if (ewdsData) {
    var ewdsUserRows = ewdsData.map(function (ewdsUser) {
    return (
    <EwdsUserRow ewdsUser={ewdsUser} key={counter++} />
    );
    });
    }
    return (
    <div className="ewdsUserTable" >
    <table id="mytable" className="table table-striped table-bordered table-condensed fixed">
    <caption>EWDS Users</caption>
    <thead>
    <tr>
    <th className="sort" type="string">User Name</th>
    <th className="sort" type="string">Email Address</th>
    <th>Pwd Changed</th>
    <th type="date">Last Logon</th>
    <th>Locked</th>
    <th className="sort" type="string">Disabled</th>
    <th></th>
    </tr>
    </thead>
    <tbody>
    {ewdsUserRows}
    </tbody>
    </table>
    </div>
    );


    };



    Here's where I'm actually displaying the data.



    class EwdsUserRow extends React.Component {     

    render() {
    const {UserName, EmailAddress, AccountCreated, PasswordChanged, AccountName,
    Locked, Enabled} = this.props.ewdsUser;

    return (
    <tr>
    <td>{UserName}</td>
    <td>{EmailAddress}</td>
    <td>{AccountCreated}</td>
    <td>{PasswordChanged}</td>
    <td>{Locked}</td>
    <td>{Enabled}</td>
    </tr>
    );
    }
    }





    share|improve this answer





















    • Thanks for your answer but here i am facing one issue where I have to paste the url. Kindly make a simple helloworld reactnative app where it will be showing a username and posting username using webservices. Please
      – Ali Ghaffari
      Nov 25 at 9:39













    up vote
    0
    down vote










    up vote
    0
    down vote









    class EwdsUserBox extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
    data:
    };
    }
    loadCommentsFromServer(page=0, count=25) {
    const xhr = new XMLHttpRequest();
    let params = "?page="+page+"&count=" + count;
    xhr.open('get', this.props.url, true);
    xhr.onload = function() {
    var data = JSON.parse(xhr.responseText);
    this.setState({ data: data});
    }.bind(this);
    xhr.send();
    }
    componentDidMount() {
    this.loadCommentsFromServer(0,25);
    }
    render() {
    const ewds = this.state.data;
    var count = 0;

    return (
    <div className="ewdsUserBox body-content">
    <EwdsUserSummary total={ewds.length} disabled={count} locked={0}/>
    <EwdsUserTable data={ewds} />
    </div>
    );

    }
    }


    This is for ReactJS but you'll notice I'm using an XMLHttpRequest to retrieve the JSON data. EwdsUserBox is just my container component. I'll then pass this data to subcomponents, in this case a user table and user row.



    const EwdsUserTable = (props) => {   
    let counter = 0;
    let ewdsData = props.data;
    if (ewdsData) {
    var ewdsUserRows = ewdsData.map(function (ewdsUser) {
    return (
    <EwdsUserRow ewdsUser={ewdsUser} key={counter++} />
    );
    });
    }
    return (
    <div className="ewdsUserTable" >
    <table id="mytable" className="table table-striped table-bordered table-condensed fixed">
    <caption>EWDS Users</caption>
    <thead>
    <tr>
    <th className="sort" type="string">User Name</th>
    <th className="sort" type="string">Email Address</th>
    <th>Pwd Changed</th>
    <th type="date">Last Logon</th>
    <th>Locked</th>
    <th className="sort" type="string">Disabled</th>
    <th></th>
    </tr>
    </thead>
    <tbody>
    {ewdsUserRows}
    </tbody>
    </table>
    </div>
    );


    };



    Here's where I'm actually displaying the data.



    class EwdsUserRow extends React.Component {     

    render() {
    const {UserName, EmailAddress, AccountCreated, PasswordChanged, AccountName,
    Locked, Enabled} = this.props.ewdsUser;

    return (
    <tr>
    <td>{UserName}</td>
    <td>{EmailAddress}</td>
    <td>{AccountCreated}</td>
    <td>{PasswordChanged}</td>
    <td>{Locked}</td>
    <td>{Enabled}</td>
    </tr>
    );
    }
    }





    share|improve this answer












    class EwdsUserBox extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
    data:
    };
    }
    loadCommentsFromServer(page=0, count=25) {
    const xhr = new XMLHttpRequest();
    let params = "?page="+page+"&count=" + count;
    xhr.open('get', this.props.url, true);
    xhr.onload = function() {
    var data = JSON.parse(xhr.responseText);
    this.setState({ data: data});
    }.bind(this);
    xhr.send();
    }
    componentDidMount() {
    this.loadCommentsFromServer(0,25);
    }
    render() {
    const ewds = this.state.data;
    var count = 0;

    return (
    <div className="ewdsUserBox body-content">
    <EwdsUserSummary total={ewds.length} disabled={count} locked={0}/>
    <EwdsUserTable data={ewds} />
    </div>
    );

    }
    }


    This is for ReactJS but you'll notice I'm using an XMLHttpRequest to retrieve the JSON data. EwdsUserBox is just my container component. I'll then pass this data to subcomponents, in this case a user table and user row.



    const EwdsUserTable = (props) => {   
    let counter = 0;
    let ewdsData = props.data;
    if (ewdsData) {
    var ewdsUserRows = ewdsData.map(function (ewdsUser) {
    return (
    <EwdsUserRow ewdsUser={ewdsUser} key={counter++} />
    );
    });
    }
    return (
    <div className="ewdsUserTable" >
    <table id="mytable" className="table table-striped table-bordered table-condensed fixed">
    <caption>EWDS Users</caption>
    <thead>
    <tr>
    <th className="sort" type="string">User Name</th>
    <th className="sort" type="string">Email Address</th>
    <th>Pwd Changed</th>
    <th type="date">Last Logon</th>
    <th>Locked</th>
    <th className="sort" type="string">Disabled</th>
    <th></th>
    </tr>
    </thead>
    <tbody>
    {ewdsUserRows}
    </tbody>
    </table>
    </div>
    );


    };



    Here's where I'm actually displaying the data.



    class EwdsUserRow extends React.Component {     

    render() {
    const {UserName, EmailAddress, AccountCreated, PasswordChanged, AccountName,
    Locked, Enabled} = this.props.ewdsUser;

    return (
    <tr>
    <td>{UserName}</td>
    <td>{EmailAddress}</td>
    <td>{AccountCreated}</td>
    <td>{PasswordChanged}</td>
    <td>{Locked}</td>
    <td>{Enabled}</td>
    </tr>
    );
    }
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 at 2:10









    Charles Owen

    51547




    51547












    • Thanks for your answer but here i am facing one issue where I have to paste the url. Kindly make a simple helloworld reactnative app where it will be showing a username and posting username using webservices. Please
      – Ali Ghaffari
      Nov 25 at 9:39


















    • Thanks for your answer but here i am facing one issue where I have to paste the url. Kindly make a simple helloworld reactnative app where it will be showing a username and posting username using webservices. Please
      – Ali Ghaffari
      Nov 25 at 9:39
















    Thanks for your answer but here i am facing one issue where I have to paste the url. Kindly make a simple helloworld reactnative app where it will be showing a username and posting username using webservices. Please
    – Ali Ghaffari
    Nov 25 at 9:39




    Thanks for your answer but here i am facing one issue where I have to paste the url. Kindly make a simple helloworld reactnative app where it will be showing a username and posting username using webservices. Please
    – Ali Ghaffari
    Nov 25 at 9:39










    up vote
    0
    down vote













    Here's the web service part. Let's say I'm just returning a corporate leader to the client. I can either create a Web API controller or an MVC controller that returns a JsonResult. leader here is merely a Leader c# object. I've chosen the latter. The key here is that we're returning JSON data back to the client in the form of a JSON object.



        [HttpGet]
    public JsonResult Leader() {
    return Json(leader, JsonRequestBehavior.AllowGet);
    }


    Let's assume the endpoint of this service will be: http://www.example.com/Leader. Now my React Native app is going to need to reference this url There are various apis for retrieving data from a web service, but I like using Fetch or you could use Axios, etc. My example below will be using Fetch. For the most basic React Native app, we'd just using the componentDidMount() event to run the Fetch request, and put leader in a state object. Note: This is an oversimplified answer and I haven't tested it out.



    import React, {Component} from 'react';
    import { Text, Card } from 'react-native';

    export default class MyComponent extends Component {
    constructor(props) {
    super(props);
    this.state = {
    leader = {},
    errMessage = ''
    }
    }

    componentDidMount() {
    fetch(url)
    .then(response => {
    if (response.ok) {
    return response;
    } else {
    let error = new Error('Error ' + response.status + ': ' + response.statusText);
    error.response = response;
    throw error;
    }
    },
    error => {
    let errmess = new Error(error.message);
    throw errmess;
    })
    .then(response => response.json())
    .then(leaders => {
    this.setState({ leader: leader });
    })
    .catch(error => {
    this.setState({ errMessage: error.message });
    });
    }
    render () {
    const {lastName, firstName} = this.state.leader;
    return (
    <Card
    title="Our beloved leader">
    <Text>`${firstName} ${lastName}/></Text>
    </Card>
    );
    }
    }





    share|improve this answer



























      up vote
      0
      down vote













      Here's the web service part. Let's say I'm just returning a corporate leader to the client. I can either create a Web API controller or an MVC controller that returns a JsonResult. leader here is merely a Leader c# object. I've chosen the latter. The key here is that we're returning JSON data back to the client in the form of a JSON object.



          [HttpGet]
      public JsonResult Leader() {
      return Json(leader, JsonRequestBehavior.AllowGet);
      }


      Let's assume the endpoint of this service will be: http://www.example.com/Leader. Now my React Native app is going to need to reference this url There are various apis for retrieving data from a web service, but I like using Fetch or you could use Axios, etc. My example below will be using Fetch. For the most basic React Native app, we'd just using the componentDidMount() event to run the Fetch request, and put leader in a state object. Note: This is an oversimplified answer and I haven't tested it out.



      import React, {Component} from 'react';
      import { Text, Card } from 'react-native';

      export default class MyComponent extends Component {
      constructor(props) {
      super(props);
      this.state = {
      leader = {},
      errMessage = ''
      }
      }

      componentDidMount() {
      fetch(url)
      .then(response => {
      if (response.ok) {
      return response;
      } else {
      let error = new Error('Error ' + response.status + ': ' + response.statusText);
      error.response = response;
      throw error;
      }
      },
      error => {
      let errmess = new Error(error.message);
      throw errmess;
      })
      .then(response => response.json())
      .then(leaders => {
      this.setState({ leader: leader });
      })
      .catch(error => {
      this.setState({ errMessage: error.message });
      });
      }
      render () {
      const {lastName, firstName} = this.state.leader;
      return (
      <Card
      title="Our beloved leader">
      <Text>`${firstName} ${lastName}/></Text>
      </Card>
      );
      }
      }





      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        Here's the web service part. Let's say I'm just returning a corporate leader to the client. I can either create a Web API controller or an MVC controller that returns a JsonResult. leader here is merely a Leader c# object. I've chosen the latter. The key here is that we're returning JSON data back to the client in the form of a JSON object.



            [HttpGet]
        public JsonResult Leader() {
        return Json(leader, JsonRequestBehavior.AllowGet);
        }


        Let's assume the endpoint of this service will be: http://www.example.com/Leader. Now my React Native app is going to need to reference this url There are various apis for retrieving data from a web service, but I like using Fetch or you could use Axios, etc. My example below will be using Fetch. For the most basic React Native app, we'd just using the componentDidMount() event to run the Fetch request, and put leader in a state object. Note: This is an oversimplified answer and I haven't tested it out.



        import React, {Component} from 'react';
        import { Text, Card } from 'react-native';

        export default class MyComponent extends Component {
        constructor(props) {
        super(props);
        this.state = {
        leader = {},
        errMessage = ''
        }
        }

        componentDidMount() {
        fetch(url)
        .then(response => {
        if (response.ok) {
        return response;
        } else {
        let error = new Error('Error ' + response.status + ': ' + response.statusText);
        error.response = response;
        throw error;
        }
        },
        error => {
        let errmess = new Error(error.message);
        throw errmess;
        })
        .then(response => response.json())
        .then(leaders => {
        this.setState({ leader: leader });
        })
        .catch(error => {
        this.setState({ errMessage: error.message });
        });
        }
        render () {
        const {lastName, firstName} = this.state.leader;
        return (
        <Card
        title="Our beloved leader">
        <Text>`${firstName} ${lastName}/></Text>
        </Card>
        );
        }
        }





        share|improve this answer














        Here's the web service part. Let's say I'm just returning a corporate leader to the client. I can either create a Web API controller or an MVC controller that returns a JsonResult. leader here is merely a Leader c# object. I've chosen the latter. The key here is that we're returning JSON data back to the client in the form of a JSON object.



            [HttpGet]
        public JsonResult Leader() {
        return Json(leader, JsonRequestBehavior.AllowGet);
        }


        Let's assume the endpoint of this service will be: http://www.example.com/Leader. Now my React Native app is going to need to reference this url There are various apis for retrieving data from a web service, but I like using Fetch or you could use Axios, etc. My example below will be using Fetch. For the most basic React Native app, we'd just using the componentDidMount() event to run the Fetch request, and put leader in a state object. Note: This is an oversimplified answer and I haven't tested it out.



        import React, {Component} from 'react';
        import { Text, Card } from 'react-native';

        export default class MyComponent extends Component {
        constructor(props) {
        super(props);
        this.state = {
        leader = {},
        errMessage = ''
        }
        }

        componentDidMount() {
        fetch(url)
        .then(response => {
        if (response.ok) {
        return response;
        } else {
        let error = new Error('Error ' + response.status + ': ' + response.statusText);
        error.response = response;
        throw error;
        }
        },
        error => {
        let errmess = new Error(error.message);
        throw errmess;
        })
        .then(response => response.json())
        .then(leaders => {
        this.setState({ leader: leader });
        })
        .catch(error => {
        this.setState({ errMessage: error.message });
        });
        }
        render () {
        const {lastName, firstName} = this.state.leader;
        return (
        <Card
        title="Our beloved leader">
        <Text>`${firstName} ${lastName}/></Text>
        </Card>
        );
        }
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 7 at 23:54

























        answered Dec 7 at 13:40









        Charles Owen

        51547




        51547






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380510%2fhow-to-connect-react-native-app-with-asp-net-web-services-using-sql-server%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin