当前位置: 代码迷 >> Web Service >> 对webservice的路径重写有关问题,
  详细解决方案

对webservice的路径重写有关问题,

热度:385   发布时间:2012-01-22 22:38:43.0
对webservice的路径重写问题,急,在线等!!
C# code

<?xml version="1.0" encoding="utf-8"?>
<configuration>

    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="rest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
        <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
    </configSections>
        <connectionStrings/>
    <system.web>
      <httpHandlers>
        <add verb="*" path="*" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
        <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
        <add verb="*" path="*.asmx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
      </httpHandlers>
      <compilation debug="true" >
        <assemblies>
          <add assembly="MySql.Data, Version=6.2.3.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
        </assemblies>
      </compilation>
      <webServices>
        <protocols>
          <add name="HttpSoap"/>
          <add name="HttpPost"/>
          <add name="HttpGet"/>
          <add name="Documentation"/>
        </protocols>
      </webServices>
       <authentication mode="Windows" />
        </system.web>

        
    <RewriterConfig>
      <Rules>
        <RewriterRule>
          <LookFor>~/WebForm99</LookFor>
          <SendTo>~/WebForm1.aspx</SendTo>
        </RewriterRule>
        <RewriterRule>
          <LookFor>~/Test</LookFor>
          <SendTo>~/Service1\.asmx/Test</SendTo>
        </RewriterRule>
      </Rules>
    </RewriterConfig>
</configuration>



在webservice中有Test这个函数,想通过访问 ***.***.***/Test ,直接访问到 ***.***.***/Service1.asmx/Test。
现在访问***.***.***/Service1.asmx/Test 这个地址提示错误,不进行URL重写前,这个地址是可以访问的:
C# code
无法将类型为“rest.Service1”的对象强制转换为类型“System.Web.IHttpHandler”。


访问***.***.***/Test ,错误:“/Service1.asmx/Test”不存在。


------解决方案--------------------
你得按照你url重写的格式去访问
------解决方案--------------------
C# code
<LookFor>~/Test</LookFor>
          <SendTo>~/Service1\.asmx/Test</SendTo>
这里好像不应该这么写
<LookFor>~/Test</LookFor>
          <SendTo>~/Service1\.asmx</SendTo>

直接应该这样吧! 
  相关解决方案