Hi,
I want to create rest method that can support request/responce in both xml and json formats.
I am trying in bellow way, but its not working getting error.
any idea on this?
Code in IService.cs :
[OperationContract]
[WebGet(UriTemplate = "/Login/{UserID}/{Password}")]
Responce Login(string UserID, string Password);
Code in Service.cs :
public Responce Login(string UserID, string Password)
{
try
{
objResponce = new Responce();
objResponce.MessageType = Responce.ResponceType.Warning.ToString();
string Con = GetConnectionString(UserID, Password); //Method to check valid user or not
if (Con.Trim().Length != 0)
objResponce.Message = "you have logged in Successfully";
else
objResponce.Message = "Please Enter Valid UserID,Password";
}
catch (Exception ex)
{
through ex;
}
return objResponce;
}
My Config settings :
<services>
<service name="OnePointAPI.OnePointAPIService">
<endpoint address="JSON" binding="webHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="webJSON" ></endpoint>
<endpoint address="XML" binding="basicHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="webXML" ></endpoint>
</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="webJSON">
<webHttp defaultOutgoingResponseFormat="Json"/>
</behavior>
<behavior name="webXML">
<webHttp defaultOutgoingResponseFormat="Xml" />
</behavior>
</endpointBehaviors>
</behaviors>
I want to create rest method that can support request/responce in both xml and json formats.
I am trying in bellow way, but its not working getting error.
any idea on this?
Code in IService.cs :
[OperationContract]
[WebGet(UriTemplate = "/Login/{UserID}/{Password}")]
Responce Login(string UserID, string Password);
Code in Service.cs :
public Responce Login(string UserID, string Password)
{
try
{
objResponce = new Responce();
objResponce.MessageType = Responce.ResponceType.Warning.ToString();
string Con = GetConnectionString(UserID, Password); //Method to check valid user or not
if (Con.Trim().Length != 0)
objResponce.Message = "you have logged in Successfully";
else
objResponce.Message = "Please Enter Valid UserID,Password";
}
catch (Exception ex)
{
through ex;
}
return objResponce;
}
My Config settings :
<services>
<service name="OnePointAPI.OnePointAPIService">
<endpoint address="JSON" binding="webHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="webJSON" ></endpoint>
<endpoint address="XML" binding="basicHttpBinding" contract="OnePointAPI.IOnePointAPIService" behaviorConfiguration="webXML" ></endpoint>
</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="webJSON">
<webHttp defaultOutgoingResponseFormat="Json"/>
</behavior>
<behavior name="webXML">
<webHttp defaultOutgoingResponseFormat="Xml" />
</behavior>
</endpointBehaviors>
</behaviors>
Anwar Shaik