C# VS 2010中的WCF端点地址
我有一个简单的web服务。这是在使用VS 2010的网站上使用的。我在VS2010中使用“添加服务引用”选项添加了服务引用。它很好用。它将服务地址打印为。但当我在浏览器中键入此服务地址时,它会显示HTTP错误400 注意:当我将服务端点中的address=“MyFolder”替换为address=”“时,将显示结果 我应该在浏览器中键入什么正确地址才能获得地址为“MyFolder”的服务 页面:C# VS 2010中的WCF端点地址,c#,.net,wcf,wcf-binding,wcf-client,C#,.net,Wcf,Wcf Binding,Wcf Client,我有一个简单的web服务。这是在使用VS 2010的网站上使用的。我在VS2010中使用“添加服务引用”选项添加了服务引用。它很好用。它将服务地址打印为。但当我在浏览器中键入此服务地址时,它会显示HTTP错误400 注意:当我将服务端点中的address=“MyFolder”替换为address=”“时,将显示结果 我应该在浏览器中键入什么正确地址才能获得地址为“MyFolder”的服务 页面: namespace ClientWebApp { public partial class De
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>
尝试将“?wsdl”添加到您正在尝试使用的url的末尾 尝试将“?wsdl”添加到您正在尝试使用的url的末尾 请看一下这个问题的答案: 引述: 在IIS中承载WCF服务时,服务的基址使用以下格式形成: {protocol}://{host}:{port}/{applicationName}/{svcFileName}。这是 您可以浏览以获取WCF帮助页和/或 元数据(在默认配置上) 形成端点的实际地址(客户端需要的地址 要使用),请使用以下格式: {serviceBaseAddress}/{endpointAddress}
在您的例子中,
{endpointAddress}
是MyFolder
,这解释了为什么您可以使用http://localhost:3187/Service1.svc/MyFolder
地址。但是,这不是显示帮助页面和元数据信息的地址,因此您在http://.../*.svc/MyFolder
并不奇怪。请查看此问题的答案:
引述:
在IIS中承载WCF服务时,服务的基址使用以下格式形成:
{protocol}://{host}:{port}/{applicationName}/{svcFileName}。这是
您可以浏览以获取WCF帮助页和/或
元数据(在默认配置上)
形成端点的实际地址(客户端需要的地址
要使用),请使用以下格式:
{serviceBaseAddress}/{endpointAddress}
在您的例子中,
{endpointAddress}
是MyFolder
,这解释了为什么您可以使用http://localhost:3187/Service1.svc/MyFolder
地址。但是,这不是显示帮助页面和元数据信息的地址,因此您在http://.../*.svc/MyFolder
并不奇怪。“但是,这不是显示帮助页面和元数据信息的地址”。您能告诉我它将在哪里吗?{protocol}://{host}:{port}/{applicationName}/{svcFileName}
=>所以在您的情况下http://localhost:3187/Service1.svc
。要查看合同,请转到http://localhost:3187/Service1.svc?wsdl
“但是,这不是显示帮助页面和元数据信息的地址”。您能告诉我它将在哪里吗?{protocol}://{host}:{port}/{applicationName}/{svcFileName}
=>所以在您的情况下http://localhost:3187/Service1.svc
。要查看合同,请转到http://localhost:3187/Service1.svc?wsdl
。