每次都会动态生成WCF服务URL的一部分

时间:2014-10-08 09:51:03

标签: c# asp.net wcf iis

我是WCF服务的全新版本。 我已经开发了这个REST WCF服务(路由服务)。

我的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后,我得到这样的URL:

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

如果我将它发布到IIS,每次都会像动态生成一个令牌(S(2wpucy0oasurckuompimgqdo))。

我不知道我哪里错了。我是否必须在IIS / Code /中进行一些更改它只是这样工作。我想要一个静态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>();
    }

  }
}   

1 个答案:

答案 0 :(得分:0)

&#34;(S(2wpucy0oasurckuompimgqdo))&#34;是添加到url的会话标识。因此,要从URL中删除它,您应该只禁用会话存储或将其移动到cookie。即要禁用会话状态,您可以将以下内容添加到配置文件中:

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

有关详细信息,请参阅MSDN上的以下文章 - ASP.NET Session State OverviewSession-State Modes