您可以在两个不同的端点中公开该服务.在SOAP一个可以使用绑定的支持SOAP例如basicHttpBinding,在RESTFUL一个可以使用webHttpBinding.我假设您的REST服务将在JSON,在这种情况下,您需要使用以下行为配置配置两个端点
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
Run Code Online (Sandbox Code Playgroud)
您的方案中的端点配置示例如下
<services>
<service name="TestService">
<endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
<endpoint address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="ITestService"/>
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
应用[WebGet]操作合同使其成为RESTful.例如
public interface ITestService
{
[OperationContract]
[WebGet]
string HelloWorld(string text)
}
Run Code Online (Sandbox Code Playgroud)
添加服务引用后SOAP服务的SOAP请求客户端端点配置,
<client>
<endpoint address="http://www.example.com/soap" binding="basicHttpBinding"
contract="ITestService" name="BasicHttpBinding_ITestService" />
</client>
Run Code Online (Sandbox Code Playgroud)
在C#中
TestServiceClient client = new TestServiceClient();
client.GetAccount("A123");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8522 次 |
| 最近记录: |