我创建了一个服务,然后我看到一个页面说:
您已创建了一项服务.
要测试此服务,您需要创建一个客户端并使用它来调用该服务.您可以使用命令行中的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>
Run Code Online (Sandbox Code Playgroud)
更新:
嗨马克,
我的配置是:
<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>
Run Code Online (Sandbox Code Playgroud)
所以基本上我浏览到.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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
该服务既可以是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();
}
}
Run Code Online (Sandbox Code Playgroud)