Viv*_*ndi 6 wcf web-services svc
通常当我实现第三方WCF Web服务时,我会得到一个以.svc
扩展名结尾的URL .
我刚刚在VS2010中创建了一个WCF Web服务,我可以运行该服务,但我没有在Test Client中看到以.svc
扩展名结尾的任何URL .
为了获得这样的URL,我还需要做些什么吗?因为通常从那里人们能够通过添加?wsdl
到最终来获得WSDL :
http://site.com/service1.svc?wsdl
如何在我的Web服务中生成这样的URL?
这就是我在App.Config中所拥有的:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="TestWebservice.Test">
<endpoint address="" binding="wsHttpBinding" contract="TestWebservice.ITest">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/TestWebservice/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我mexHttpBinding
从配置文件中删除了端点.当我启动我的Web服务时,它会自动显示WSDL的URL:
http://localhost:8732/Design_Time_Addresses/TestWebservice/?wsdl
Run Code Online (Sandbox Code Playgroud)
将/
在之前?wsdl
的部分似乎是非常重要的.否则它将无法工作.
但这仍然让我想到了我的最后一个问题.如何指定.svc
文件的URL ?我想要一个像这样的网址:http://localhost:8732/Design_Time_Addresses/TestWebservice/Test.svc?wsdl
我进一步了.我读到这个:http://msdn.microsoft.com/en-us/library/aa751792.aspx
所以我Test.svc
使用以下代码在项目的根目录中创建了一个文件:
<% @ServiceHost Service="TestWebservice.ITest" %>
Run Code Online (Sandbox Code Playgroud)
然后我尝试svc
通过以下URL 访问我的文件,但两者都不适合我:
http://localhost:8732/Design_Time_Addresses/TestWebservice/Test.svc
http://localhost:8732/Design_Time_Addresses/Test.svc
Run Code Online (Sandbox Code Playgroud)
甚至可以托管svc
Visual Studio内部?或者我真的需要先在IIS中托管它吗?
我终于有了它的工作!我重新添加mexHttpBinding
到我的App.Config.
我安装了IIS7.将Web Service发布到我的C:\
驱动器中的文件夹.然后在IIS中映射该文件夹并尝试.svc
在浏览器中请求该文件.
起初它对我不起作用,因为它不承认.svc
扩展.然后我所要做的就是输入以下cmd:aspnet_regiis.exe -i
现在一切正常.
现在一切似乎都很好.猜测,.svc
当Visual Studio托管服务时,您无法请求文件.但它在IIS中托管时有效.