end point not found in wcf restful service through iis - wcf

i am just checking whether the method is working or not .but i am getting end point not found .
in the url i provided the link as below:
http://localhost/WcfService1/Service1.svc/kuna/hai
// my web.config file://
<services>
<service name="WcfService1.Service1">
<endpoint address="" behaviorConfiguration="restfulBehaviour" binding="webHttpBinding" bindingConfiguration="" contract="WcfService1.IService1"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfService1/Service1.svc"/>
</baseAddresses>
</host>
</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="restfulBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
---------------------------------------------------------
my service file
jus passing two parameters as input and expecting true as o/p
public class Service1 : IService1
{
public bool CheckLoginDetails(string UN, string P)
{
return true;
}
}
interface for service file:
Iservice file:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "CheckLoginDetails/{UN}/{P}")]
bool CheckLoginDetails(string UN, string P);
}

sorry i forgot to give the method name in the url.
the url should be :
http://localhost/WcfService1/Service1.svc/CheckLoginDetails/kuna/hai

Related

WCF Service Error 400 Bad Request In VS2017

I have a very simple WCF Service Project in VS2017. But I keep getting error 400 when I try to visit the endpoints. I have read the other questions posted here about the same issue and I have tried them with no luck so far.
My Service Contract:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetData/{value}")]
string GetData(string value);
}
My Service:
public class Service : IService
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
}
My Web.Config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="myBehavior" name="WCGFService1.Service">
<endpoint address="" contract="WCGFService1.IService" binding="webHttpBinding">
</endpoint>
</service>
</services>
When I visit http://localhost:61648/Service.svc/GetData/12, I get HTTP 400 Bad Request. I've tried with browser and POSTman. What am I doing wrong?
I am using VS2017. My IService.cs and Service.cs are inside the App_Code folder whereas the
Service.svc is in the root folder. Also, when I try to add the name & contract in web.config, VS2013 suggests me the namespace and the interface/class name, whereas, VS2017 is not suggesting me anything so I have to manually type it.
Also, in VS2013, the Interface and Class were located in the root folder instead of the App_Code folder. The project is a WCF Application in VS2017. My .NET Version is 4.5.2.
Fixed it, had a few problems in the web.config file:
<system.serviceModel>
<behaviors>
<!-- Fix 1: Added a endpointBehavoir with webHttp -->
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!-- Fix 2: Instead of using the full name (WCGFService1.Service), used just the class name (Service) -->
<service behaviorConfiguration="myBehavior" name="Service">
<!-- Fix 3: Same thing here, used just the IService instead of full name, also, used the aforementioned endpointBehavoir -->
<endpoint address="" contract="IService" binding="webHttpBinding" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
That did it for me, for whatever reason, in VS2013, it would not work if you don't provide the full name (namespace and class/interface name) but in VS2017, it works only if you provide just the class/interface name.

WCF Serice Not working in REST

I am trying to create custom wcf servic on sharepoint.
Unfoortuntly the service is working fine with WCF Test Client, But when i tried to access it through web/browser it is giving me empty screen or empty result in responce
Please some one assist me, Thank you so much in advance
Interface
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "/GetAllB/{value1}",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetAllB(int val);
Method
public string GetAllB(int val)
{
return "Enterted Value is this" + val;
}
Web.config File
<behaviors>
<serviceBehaviors>
<behavior name="Kuservice.Service1ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deploying the solution. -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deploying the solution to avoid disclosing exception information. -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
You can consider changing your config file to something like below,
<configuration>
<system.serviceModel>
<services>
<service name="WcfJsonRestService.Service1">
<endpoint address="http://localhost:8732/service1"
binding="webHttpBinding"
contract="WcfJsonRestService.IService1"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

How to configure endpoint

I had a WCF Service
My Web.config looks like this:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyNameSpace.MyService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="crossDomain" contract="MyNameSpace.IMyService" behaviorConfiguration="EndpBehavior"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
I recently found this code for array parameter from one of the website
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Web;
namespace ArraysInQueryStrings
{
public class ArrayInQueryStringWebHttpBehavior : WebHttpBehavior
{
WebMessageFormat defaultOutgoingResponseFormat;
public ArrayInQueryStringWebHttpBehavior()
{
this.defaultOutgoingResponseFormat = WebMessageFormat.Json;
}
public override WebMessageFormat DefaultOutgoingResponseFormat
{
get
{
return this.defaultOutgoingResponseFormat;
}
set
{
this.defaultOutgoingResponseFormat = value;
}
}
protected override QueryStringConverter GetQueryStringConverter(OperationDescription operationDescription)
{
return new ArrayQueryStringConverter();
}
}
}
How to use this extended class in the web.config.
It seems to be an Endpoint behaviour but dont know how to use it.
Any help is appreciated
To add custom behaviors, you need to add your derived behavior as a behavior extension in config file and need to add a new Behavior extension type. Refer to this post - Custom Behavior won't register in my web.config
public class ArrayInQueryStringBehaviorExtension : BehaviorExtensionElement
{
public override Type BehaviorType
{
get { return typeof(ArrayInQueryStringWebHttpBehavior);
}
}
protected override object CreateBehavior()
{
return new ArrayInQueryStringWebHttpBehavior();
}
}
Config file (you need to specify your assembly name where I have marked square brackets below)
<extensions>
<behaviorExtensions>
<add name=" ArrayInQueryStringWebHttpBehavior " type="[Namespace]. ArrayInQueryStringBehaviorExtension, [Assembly Name], [Assembly Version], [Assembly Culture], PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="arrayInQueryBehavior">
<webHttp/>
< ArrayInQueryStringWebHttpBehavior />
</behavior>
</endpointBehaviors>
<behaviors>

Consume Wcf Rest Service Issue

I have created a Rest WCF Service.
Service Contract
[ServiceContract]
public interface IPracticeService
{
[OperationContract]
int AddInt(int value1, int value2);
[OperationContract]
double AddDouble(double value1, double value2);
[OperationContract]
string Hello();
[OperationContract]
Person GetPerson();
}
Class
public class PracticeService : IPracticeService
{
public int AddInt(int value1, int value2)
{
return value1 + value2;
}
[OperationBehavior]
public double AddDouble(double value1, double value2)
{
return value1 + value2;
}
public string Hello()
{
return "hello";
}
[WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json)]
public Person GetPerson()
{
Person p = new Person();
p.Name = "Abc";
p.Age = 5;
return p;
}
Web Config
<system.serviceModel>
<services>
<service name="RestService.IRestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="*" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="web"></behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
So When I want Add ServiceRefrence This In the client It is giving me error.
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://mydomain:1121/Rest/RestServiceImpl.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://mydomain:1121/Rest/RestServiceImpl.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
So How can it will be resolved.
You need to modify your config like this ,
<system.serviceModel>
<services>
<service name="PracticeService.IPracticeService" behaviorConfiguration="ServiceBehaviour">
<endpoint address="*" binding="webHttpBinding" contract="PracticeService.IPracticeService" behaviorConfiguration="web"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="web"></behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

Invoking WCF service in browser similar to asmx

I have made a WCF service in NET 4.0 and it returns the XML, I have tested it using SoapUI and i can see the required response xml. But my WCF service would be called by 3rd party software and they want to use it through a URL like asmx. I have googled and found that i need to make using REST guidelines. However i have not found a proper link showing making web-service using REST and then accessing the method from the browwer similar to web services.
Below is the interface code which i have used to return the format in XML
public interface IService1
{
[WebGet(
UriTemplate = "/GetDocument/",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Xml)]
[OperationContract, XmlSerializerFormat]
XmlElement GetDocument();
// TODO: Add your service operations here
}
Below is my config settings.
<system.serviceModel>
<services>
<service name="BritishLandXML.BritishLandXML1" behaviorConfiguration="metadataBehavior">
<endpoint address="" binding="basicHttpBinding" contract="BritishLandXML.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding>
<security mode="None"></security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="rest">
<webHttp helpEnabled="true" faultExceptionEnabled="true" automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
Please let me know how can i achieve this and what exact settings will be required.