我有一個簡單的Web服務。這是在使用VS 2010的網站中使用的。我在VS 2010中使用「添加服務引用」選項添加了服務引用。它工作正常。它打印的服務地址爲http://localhost:3187/Service1.svc/MyFolder。但是,當我在瀏覽器中輸入此服務地址時,它顯示HTTP錯誤400.VS 2010中的WCF端點地址
注意:當我在服務的終點將address =「MyFolder」替換爲address =「」時,http://localhost:3187/Service1.svc顯示結果。
什麼是正確的地址,我應該在瀏覽器中輸入「MyFolder」的地址獲得服務?
頁:
namespace ClientWebApp
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Service1Client myClientService = new Service1Client();
Response.Write(myClientService.Endpoint.Address);
string result = myClientService.GetData(7);
lblName.Text = result;
}
}
}
合同:
namespace MyWCFServiceApplication
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
public class MyService : IService1
{
public string GetData(int value)
{
return string.Format("Now entered: {0}", value);
}
}
}
配置:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="MyWCFServiceApplication.MyService"
behaviorConfiguration="WeatherServiceBehavior">
<endpoint address="MyFolder"
binding="wsHttpBinding"
contract="MyWCFServiceApplication.IService1" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
「但是,這不是您的幫助頁面和元數據信息呈現的地址。」你能告訴我它會在哪裏嗎? – Lijo
'{protocol}:// {host}:{port}/{applicationName}/{svcFileName}'=>所以在你的情況下'http:// localhost:3187/Service1.svc'。要查看合同,請轉到'http:// localhost:3187/Service1.svc?wsdl'。 – nowaq