I'm trying to create a WCF web service with JSON and Consume with Client in ASP .NET My WCF web server is up and running hosted on IIS, I have checked with browser, getting JSON response.
Here is Server web.config file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<!--<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>-->
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceApp.Service1">
<endpoint address="../Service1.svc" binding="webHttpBinding" contract="WcfServiceApp.IService1" behaviorConfiguration="webBehaviour"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior >
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept"/>
</customHeaders>
</httpProtocol>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
After that I created a Web Application Client in ASP .NET to consume WCF web service. I have added WCF web service reference in Client, But
Visual Studio 2012 not updating client web.config
. I have found few things in stackoverflow for my client web.config
Client web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<!--<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>-->
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webby">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost/WCFService/Service1.svc" name="Service1" binding="webHttpBinding"
contract="ServiceReference1.IService1" behaviorConfiguration="webby"/>
</client>
</system.serviceModel>
</configuration>
calling Service from Client
protected void Button1_Click(object sender, EventArgs e)
{
string result;
string input = tbInput.Text;
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
try
{
result = client.GetData(input);
lbResult.Text = result;
client.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
But when I tried read from Web service, getting Exception
There was no endpoint listening at http://localhost/WCFService/Service1.svc/GetData that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Inner Exception: The remote server returned an error: (404) Not Found."}
I suspect its a Configuration issue in my web.config file,, But not sure what is causing this issue.
Thanks, Ashok