我创建了一个服务,然后我看到了一个页面:
您已创建了一项服务。
要测试此服务,您需要 创建一个客户端并使用它来调用 服务。你可以使用 命令行中的svcutil.exe工具 使用以下语法:
但是如何判断它是SOAP还是REST服务呢?我如何从wsdl等告诉我们?
服务配置:
<services>
<service name="VLSContentService"
behaviorConfiguration="VLSContentServiceBehaviour" >
<endpoint name="rest"
address=""
behaviorConfiguration="VLSContentServiceEndpointBehaviour"
binding="webHttpBinding"
contract="IVLSContentServiceREST" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
contract="IVLSContentServiceREST"/>
</service>
</services>
更新:
嗨马克,
我的配置是:
<services>
<service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
<endpoint name="rest" address="" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentServiceREST" />
<endpoint name="soap" address="soap" binding="basicHttpBinding" contract="IVLSContentServiceREST"/>
</service>
</services>
所以基本上我浏览到.svc文件,我看到了wsdl的链接。但是,我如何知道SOAP或REST端点的那些。我是否正确配置了它?
由于
更新:17:49(英国时间)
<system.serviceModel>
<!---Add the service-->
<services>
<service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
<endpoint name="rest"
address=""
behaviorConfiguration="VLSContentServiceEndpointBehaviour"
binding="webHttpBinding"
contract="IVLSContentServiceREST" />
</service>
</services>
<!---Add the behaviours-->
<behaviors>
<serviceBehaviors>
<behavior name="VLSContentServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="VLSContentServiceEndpointBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
</system.serviceModel>
marc_s更新:18:22(英国时间)
Pete,试试这个 - 没有元数据发布,没有 - 只是webHttpBinding
- 你应该不再看到任何WSDL ......
<system.serviceModel>
<services>
<service name="VLSContentService">
<endpoint name="rest"
address=""
binding="webHttpBinding"
contract="IVLSContentServiceREST" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
</system.serviceModel>
答案 0 :(得分:5)
服务可以是REST和SOAP,WCF 服务可以有多个端点,包括两者的混合SOAP和REST。在WSDL上,SOAP端点将显示在wsdl:definitions / wsdl:service / wsdl:port元素中; REST端点不会。因此,如果服务中只有一个端点,那么如果WSDL中有一个wsdl:port条目,那么它就是一个SOAP端点;否则就是REST。
您可以运行下面的代码并查看wsdl,看看它只显示了一个用于SOAP端点的wsdl:port元素。
public class StackOverflow_6414181
{
[ServiceContract]
public interface ITest
{
[OperationContract]
[WebGet]
string Echo(string text);
}
public class Service : ITest
{
public string Echo(string text)
{
return text;
}
}
public static void Test()
{
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "soap");
host.AddServiceEndpoint(typeof(ITest), new WebHttpBinding(), "rest").Behaviors.Add(new WebHttpBehavior());
host.Open();
Console.WriteLine("Host opened");
Console.Write("Press ENTER to close the host");
Console.ReadLine();
host.Close();
}
}
答案 1 :(得分:4)
如果你拥有 WSDL - 它就是一个SOAP服务。
REST没有WSDL。
REST有一个类似的概念叫做 WADL - Web应用程序描述语言(WADL specification as PDF) - 但是它并没有像SOAP的WSDL那样得到很好的建立和广泛使用。