2014-10-08 47 views
0

我是WCF服務中的一個完整新功能。 我開發了這個REST WCF服務(一個路由服務)。WCF服務URL的一部分每次都會動態生成

我的web.config

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
</system.web> 

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
</system.webServer> 

<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <standardEndpoints> 
     <webHttpEndpoint> 
      <!-- 
     Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
     via the attributes on the <standardEndpoint> element below 
    --> 
      <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints> 

    <behaviors> 
     <serviceBehaviors> 
      <behavior name=""> 
       <serviceMetadata httpGetEnabled="true" policyVersion="Policy12"/> 

      </behavior> 
     </serviceBehaviors> 

    </behaviors> 
</system.serviceModel> 

它發佈到IIS我收到網址這樣的後:

http://xxxx.com:8001/ACT/(S(2wpucy0oasurckuompimgqdo))/GetUser

每次令牌像段(S(2wpu cy0oasurckuompimgqdo))會動態生成,如果我將它發佈到IIS。

我不知道我出錯的地方。無論我需要在IIS /代碼中做一些更改,它都是這樣的。我想要一個靜態URL,即使在將它重新發布到IIS後也不應該更改。

的Global.asax.cs

public class Global : HttpApplication 
    { 
     void Application_Start(object sender, EventArgs e) 
     { 
      RegisterRoutes(); 
     } 

    private void RegisterRoutes() 
    { 
     // Edit the base address of Service1 by replacing the "Service1" string below 
     RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(ACTServices))); 
    } 
} 

服務合同:

namespace ACT 
{ 


    [ServiceContract] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
public class ACTServices 
{ 


[OperationContract] 
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetUserData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] 
    [FaultContract(typeof(ExceptionHandler))] 
    public List<UserData> GetUser(UserSearchCode searchcode) 
    { 
     try 
     { 

      return objRetrieveData.GetUserfromACT(searchcode.firstName, searchcode.lastName); 
     } 
     catch (Exception e) 
     { 
      ExceptionHandler eH = new ExceptionHandler(); 
      eH.status = "Error"; 
      eH.message = e.Message; 
      throw new WebFaultException<ExceptionHandler>(eH, HttpStatusCode.InternalServerError); 
     } 
     //return new List<UserData>(); 
    } 

    } 
} 
+0

「(S(2wpucy0oasurckuompimgqdo))」是會話身份已添加到網址。因此,要從網址中刪除它,您應該禁用會話存儲或將其移至Cookie。 – 2014-10-08 10:10:40

+0

@IvanZub你能告訴我什麼應該是最好的選擇嗎?謝謝你快速的回覆。 – Deep 2014-10-08 10:23:38

+0

我相信你可以只添加以下到您的配置文件: <的sessionState模式=「關」 /> 以噸 2014-10-08 10:26:28

回答

0

「(S(2wpucy0oasurckuompimgqdo))」 是會話標識添加到URL。因此,要從網址中刪除它,您應該禁用會話存儲或將其移至Cookie。即禁用會話狀態,您可以添加以下到您的配置文件:

<system.web> 
    <sessionState mode="Off" /> 
</system.web> 

欲瞭解更多信息,請參閱MSDN上的以下文章 - ASP.NET Session State OverviewSession-State Modes