Hi,
web service work when call from local not work call from other hosting
i create web service to add data (sent from anther server) to my data
Code web service
public string SaveData(string resultData)
{
sa_asdm.DLR service = new sa_asdm.DLR();
RootObject obj = JsonConvert.DeserializeObject<RootObject>(resultData);
foreach (JsonData item in obj.results)
{
{
var connStr = ConfigurationManager.ConnectionStrings["myCon1"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
try
{
SqlCommand cmd = new SqlCommand("[insert_RDL]", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@msgId", item.msgId);
cmd.Parameters.AddWithValue("@to_mobile", item.to);
cmd.Parameters.AddWithValue("@status", item.status);
con.Open();
cmd.ExecuteNonQuery();
}
finally
{
}
}
}
return "OK ";
}
sent page for example :
<script type="text/javascript">
var json = '{"results": [{"msgId": "001","to": "9665312114","status": "D"}, {"msgId": "859911880","to": "966535112578","status": "N"}, {"msgId": "859911880","to": "966535112579","status": "S"}]}';
$.ajax({
type: "POST",
url: "http://website1.com/DLR.asmx/SaveData",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ resultData: json }),
traditional: true,
processData: false ,
success: function (data) { }
});
</script>
the web service in website1
when i post json from
same server : http://website1.com/sent.aspx
working
But when i post json from
other server for example : اttp://website2.com/sent.aspx
Not working
-------------------------------------------------------
What I have tried:
i sloved it i add this code to web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS, PUT, DELETE" />
<add name="Access-Control-Allow-Headers" value="content-type,soapaction,x-requested-with" />
</customHeaders>
</httpProtocol>
</system.webServer>