【发布时间】:2014-03-04 14:38:31
【问题描述】:
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 休息服务。我想传递用户名和密码并检查它。如果是 bob,则允许继续。
当我调用这个网址时:
http://localhost:48401/ARService/Service.svc/rest/IsValidUser?userid=bob&password=bob
然后我在我的网页上收到此错误:
未找到端点。请参阅服务帮助页面以构建对服务的有效请求。
如果有人知道如何使用此函数参数在我的情况下调用IsValidUser。请帮帮我。
【问题讨论】:
-
除了明文传输的密码外,您没有提及您的实际问题是什么。你是不是不能传参数?为什么不?您遇到了哪些问题,收到了哪些错误消息?
-
当我调用这个 url 时:-localhost:1967/RestService/callme?id=bob&value=bob 然后我得到这个错误:找不到端点。请参阅服务帮助页面以构建对服务的有效请求。在我的网页上。
-
您的网址与您的代码完全不匹配。也许你应该先确保你的服务是可调用的,然后再考虑参数和函数。
-
您的参数名称是
userid和password,但您发送的是id和value。 -
@silvermind 抱歉我编辑了我的网址