в вашем методе обслуживания, который вы вызываете, вставьте эти 4 строки кода в начало функции ниже.
public string GetEmployee(string id, string name, string email)
{
WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Methods", "GET"); WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Headers", "Content-Type, Accept");
Employee employee = new Employee();
employee.TRGEmpID = id;
employee.First_Name = name;
employee.Email = email;
EmployeeManagement empMgmt = new EmployeeManagement();
var json = new JavaScriptSerializer().Serialize(empMgmt.Search(employee).FirstOrDefault());
return json;
}
также, в файле SVC добавьте эту строку перед вашей функцией, как показано ниже.
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
string GetEmployees(string name);
если вам тоже нужен web.config, то здесь
<?xml version="1.0"?>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="EmployeeService.EmployeeSearchService" behaviorConfiguration="DefaultServiceBehavior">
<endpoint binding="webHttpBinding" contract="EmployeeService.IEmployeeSearchService" behaviorConfiguration="DefaultEPBehavior" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="DefaultEPBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>