I have created WCF service in project. Now using Jquery I am successfully able to consume service, but when I tried to add service as web reference in windows application, I am unable to invoke it. If I create simple service, I can successfully invoke in windows application, but if I do changes to invoke service for jquery, which I found by doing some Google search. I don’t know where I am missing.
Below is the code, I have done.
This is the interface for WCF.
[ServiceContract]
public interface ITestService
{
[OperationContract]
void DoWork();
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
string HelloWorld();
}
Class invoking Interface
public class TestService : ITestService
{
public void DoWork()
{
}
public string HelloWorld()
{
return "Hello World";
}
}
}
and here is the web config for the application.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="TestWCFBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="TestWCFBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
<services>
<service name="WebAppWithWCF.TestService" behaviorConfiguration="TestWCFBehavior">
<endpoint address="" binding="webHttpBinding" contract="WebAppWithWCF.ITestService" behaviorConfiguration="TestWCFBehavior"/>
</service>
</services>
</system.serviceModel>
I have done some try and error, but couldn’t found a way till now…
Please help… and let me know if any information is missing from my side.
The webHttpBinding does not expose metadata and thus you cannot add a reference to it.
Basically, the Add Service Reference feature generates proxies and classes based on what is known of the service (exposed via metadata / WDSL).
Services with wsHttpBinding or basicHttpBinding both expose your service’s metadata. They are usually used when you’re building a .NET to .NET client-server application.
Implementing both binding: WCF Service with webHttpBinding-basicHttpBinding-wcHttpBinding