如何传递多个参数WCF RESTful服务? [英] How to pass multiple parameter in wcf restful service?

查看:1778
本文介绍了如何传递多个参数WCF RESTful服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IService.cs

[OperationContract]
    [WebGet(UriTemplate = "/IsValidUser?userid={userid}&password={password}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    string IsValidUser(string userid, string password);

Service.cs

public string IsValidUser(string userid, string password)
{
    if (userid =="bob" && password =="bob")
    {
        return "True";
    }
    else
    {
        return "false";
    }
}

的web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="Service" behaviorConfiguration="ServBehave">
        <!--Endpoint for REST-->
        <endpoint address="rest" binding="webHttpBinding" behaviorConfiguration="restPoxBehavior" contract="IService"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServBehave">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <!--Behavior for the REST endpoint for Help enability-->
        <behavior name="restPoxBehavior">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

问题:

下面我的问题是,我想传递多个参数,同时呼吁 WCF休息服务但我不能够在传递多个参数WCF休息服务电话。在这里我想通过用户名和密码,并为您在它。如果它是那么鲍勃允许继续。

Here my problem is that I want to pass multiple parameter while calling wcf rest service but I am not able to pass multiple parameter in wcf rest service call.Here i want to pass userid and password and check for in it.if it is bob then allow to go ahead.

而当我调用这个网址: -

And when I am calling this url :-

<$c$c>http://localhost:48401/ARService/Service.svc/rest/IsValidUser?userid=bob&password=bob

然后我让我的网页上此错误: -

then I am getting this error on my web page:-

Endpoint not found. Please see the service help page for constructing valid requests to the service.

如果有人在我的情况下使用该功能parameter.so想法如何调用 IsValidUser 请帮助我。

If somebody have idea how to call IsValidUser in my case with this function parameter.so please help me.

推荐答案

你可以写这样的:

Iservice.cs

[OperationContract]
[WebGet(UriTemplate = "IsValidUser/{userid}/{password}")]
string IsValidUser(string userid, string password);

服务的.cs

public string IsValidUser(string userid, string password)
{
   if (userid== "root" && password== "root")
   {
      return "True";
   }
   else
   {
      return "false";
   }    
}

运行这个网址在浏览器中,那么你会得到输出
本地主机/ service.svc / REST / IsValidUser /根/根

这篇关于如何传递多个参数WCF RESTful服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆