【问题标题】:Unable to pass EmailID in wcf web service url无法在 wcf Web 服务 url 中传递 EmailID
【发布时间】:2014-04-02 06:45:29
【问题描述】:

我有一项服务,我想在我的 wcf 休息服务中传递 EmailID,但我无法在休息 url 中发送 EmailId。如果我传递简单的字符串,那么我的服务运行良好,但是当我在 url 中传递 EmailID 时,我得到以下错误。

错误

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

IService.cs

[OperationContract]
[WebGet(UriTemplate = "myservice/{username}/{email}", ResponseFormat = WebMessageFormat.Json)]
bool myservice(string username, string email);

Service.cs

public bool myservice(string username, string email)
{
     if(username != "" && email !="")
         return true;
     else
         return false;
}

web.cofig

<system.web>
   <compilation debug="true" targetFramework="4.0">
     <assemblies>
       <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
     </assemblies>
   </compilation>    
   <httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" relaxedUrlToFileSystemMapping="true"/>
   <pages validateRequest="false" />           
 </system.web>

我也试过这个。

<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />       
<pages validateRequest="false" />

当我传递简单的字符串时,我的服务运行良好,但是当我在 url 中传递 EmailID 时,我得到了上述错误。如果有人对此问题有解决方案,请帮助我。

标签

【问题讨论】:

  • emailid 中是否有“@”?该字符在 URL 中是非法的。
  • 是的,Email id 也有 @dot

标签: c# web-services wcf rest asp.net-4.0


【解决方案1】:

我尝试了所有的尝试,但最终无法在 Web 服务 url 中传递 EmailId。

我为上述问题找到了替代解决方案。但如果有人有其他解决方案,请帮助我。这个答案是可以接受的。

替代解决方案。

[OperationContract()]
[WebGet(UriTemplate = "/myservice/{username}?v={email}", ResponseFormat = WebMessageFormat.Json)]
string myservice(string username,string email);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-10
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-25
    相关资源
    最近更新 更多